PHP and JS Communication usually use JSON, but the array passed in JSON is not a standard array, but a stdClass type. Then we can refer to the following several methods for conversion.
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:
Copy the Code code as follows:
$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.
The above describes the PHP Stdclass object to the array of several methods, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.