Method 1:
Copy codeThe Code is as follows:
// Convert 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 2:
Copy codeThe Code is as follows:
$ Array = json_decode (json_encode (simplexml_load_string ($ xmlString), TRUE );
Method 3:
Copy codeThe Code is 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 data volume is 10 million, the execution should be 1 s, and the structure should be more complex. It can reach 3 s, resulting in poor performance.
You can replace it with the following:
Copy codeThe Code is as follows: function object2array (& $ object ){
$ Object = json_decode (json_encode ($ object), true );
Return $ object;
}
However, the json feature can only be for utf8. Otherwise, transcoding is required first.