PHP中把stdClass Object转array的几个方法
2014-05-08 00:00
691 查看
方法一:
方法二:
方法三:
如果是10W的数据量的话,执行要进1s,结构再复杂些,可以达到3s, 性能太差了
可以用以下替换:
但是对json的特性,只能是针对utf8的,否则得先转码下。
//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的,否则得先转码下。
相关文章推荐
- PHP中把stdClass Object转array的几个方法
- PHP中把stdClass Object转array(对象转数组)的几个方法
- PHP中把stdClass Object转array的几个方法
- php中把stdClass Object转array的几个方法
- PHP中把stdClass Object转array的几个方法
- PHP中把stdClass Object转array的几个方法
- PHP中把stdClass Object转array的几个方法
- PHP中把stdClass Object转array的几个方法
- PHP 将json的stdClass Object转成数组array 方法二
- PHP中stdClass简介及 stdClass Object转array方法
- PHP 转换stdClass Object 为 Array
- PHP中如何将stdClass Object转为array
- PHP------数组和对象相互转化,stdClass Object转array
- PHP stdClass Object转array 函数
- PHP中遍历stdclass object 报错Fatal error: Cannot use objectof type stdClass as array
- php “Cannot use object of type stdClass as array” 的解决方法
- PHP stdClass Object转array
- PHP中 json_decode 转化 为 array 及 stdclass object
- PHP stdClass Object转array
- PHP JSON出错:Cannot use object of type stdClass as array解决方法