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>