Method One:
Copy Code code as follows:
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:
Copy Code code as follows:
$array = Json_decode (Json_encode (simplexml_load_string ($xmlString)), TRUE);
Method Three:
Copy 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 it is 10W of data, the implementation to 1s, the structure more complex, can reach 3s, poor performance
You can replace it with the following:
Copy Code code as follows:
Function Object2array (& $object) {
$object = Json_decode (Json_encode ($object), true);
return $object;
}
But the characteristics of JSON, can only be directed at UTF8, otherwise you have to first transcoding.