Method One:
PHP StdClass object to array function 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:
$array = Json_decode (Json_encode (simplexml_load_string ($xmlString)), TRUE);
Method Three:
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 reach 3s, performance is poor
You can replace it with the following:
Function Object2array (& $object) { $object = Json_decode (Json_encode ($object), true); return $object; }
However, the characteristics of JSON, only for UTF8, otherwise you have to transcode.