PHP stdclass转array的方法

PHP stdclass转array的方法

<pre>
<?php
$a = new stdClass();
$a->id = '11 ';
$a->username = 'me';
print_r($a);
$b=object2array($a);
print_r($b);
function object2array($object) {
$object1 = json_decode( json_encode( $object),true);
return $object1;
}
?>
</pre>


输出结果
<pre>

stdClass Object
(
[id] => 11
[username] => me
)
Array
(
[id] => 11
[username] => me
)
</pre>


如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/

 
原文地址:https://www.cnblogs.com/newmiracle/p/11875323.html