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>

 

posted @ 2019-11-17 08:27  newmiracle宇宙  阅读(1136)  评论(0编辑  收藏  举报