例如:
<code>array(3) { [0]=> object(stdClass)#6 (2)
{ ["id"]=> string(1) "1" ["topic_name"]=> string(5) "janus" }
[1]=> object(stdClass)#7 (2)
{ ["id"]=> string(2) "10" ["topic_name"]=> string(8) "emulsion" }
[2]=> object(stdClass)#33 (2)
{ ["id"]=> string(2) "14" ["topic_name"]=> string(8) "particle" } }
</code>如果转换成数组?
例如:
<code>array(3) { [0]=> object(stdClass)#6 (2)
{ ["id"]=> string(1) "1" ["topic_name"]=> string(5) "janus" }
[1]=> object(stdClass)#7 (2)
{ ["id"]=> string(2) "10" ["topic_name"]=> string(8) "emulsion" }
[2]=> object(stdClass)#33 (2)
{ ["id"]=> string(2) "14" ["topic_name"]=> string(8) "particle" } }
</code>如果转换成数组?
不太严格要求性能且编码是 utf-8 的情况下就:
立即学习“PHP免费学习笔记(深入)”;
<code class="php">$new_array = json_decode(json_encode($array), true);</code>
如果严格要求的话,根据情况循环处理吧
Easily find JSON paths within JSON objects using our intuitive Json Path Finder
30
<code class="php">foreach ($array as $key => $value) {
$array[$key] = (array)$value;
}</code>
用foreach就可以
谢邀。
直接通过常用的->获取类属性的方式进行操作,如果需要获取当中有什么元素的化可以使用反射实现
<code class="php">$reflection = new ReflectionObject($stdClass); $properties = $target->getProperties();</code>
ReflectionObject::getProperties
写个函数,用上array_map
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号