method One: Copy the code code as follows://PHP StdClass Object goto Arrayfunction Object_array ($array) {if(Is_object ($array)) {$array=(array) $array; } if(Is_array ($array)) {foreach($array as$key =$value) {$array [$key]=Object_array ($value); } } return$array; } method Two: Copy the Code code as follows: $array=Json_decode (Json_encode (simplexml_load_string ($xmlString)), TRUE); method Three: Copy the Code code as follows: function Object2array_pre ( &$Object) { if(Is_object ($Object) {$arr= (array) ($Object); } Else{$arr= &$Object; } if(Is_array ($arr)) {foreach($arr as$varName =$varValue) {$arr [$varName]= $ This-Object2array ($varValue); } } return$arr; If the amount of data is 10W, the implementation of the 1s, the structure is more complex, can achieve 3s, poor performance can be replaced with the following: Copy code code as follows: function Object2array (&$Object) { $Object= Json_decode (Json_encode ($Object),true); return$Object; However, the JSON feature is only for UTF8, otherwise it has to be transcoded first.
PHP object to array example
function Std_class_object_to_array ($stdclassobject)
{
$_array = Is_object ($stdclassobject)? Get_object_vars ($stdclassobject): $stdclassobject;
foreach ($_array as $key = = $value) {
$value = (Is_array ($value) | | is_object ($value))? Std_class_object_to_array ($value): $value;
$array [$key] = $value;
}
return $array;
}
Several methods of transferring Stdclass object to array in PHP