When we often use the API interface to retrieve the json value returned by data, the value obtained by parsing the json_decode method is generally not an array, but an object string with stdClassObjec, if we want to obtain the corresponding PHP array, we need to use the following methods. Method 1:
// 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:
$array = json_decode(json_encode(simplexml_load_string($xmlString)),TRUE);
Method 3:
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:
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.