方法一:
//PHP stdClass Object转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;
}
方法二:
$array = json_decode(json_encode(simplexml_load_string($xmlString)),TRUE);
方法三:
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;
}
如果是10W的数据量的话,执行要进1s,结构再复杂些,可以达到3s, 性能太差了
可以用以下替换:
function object2array(&$object) {
$object = json_decode( json_encode( $object),true);
return $object;
}
但是对json的特性,只能是针对utf8的,否则得先转码下。
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn