PHP stdclass转array的方法
<?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;
}
?>
输出结果
stdClass Object
(
[id] => 11
[username] => me
)
Array
(
[id] => 11
[username] => me
)
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/19039.html