如何将对象转换为数组?<?php
print_r($response->response->docs);?>产出如下: Array (
[0] => Object
(
[_fields:private] => Array
(
[id]=>9093
[name]=>zahir )
Object
(
[_fields:private] => Array
(
[id]=>9094
[name]=>hussain )..
))如何将此对象转换为数组?我想输出以下内容:Array(
[0]=>
(
[id]=>9093
[name]=>zahir )
[1]=>
(
[id]=>9094
[name]=>hussain )...)这个是可能的吗?
3 回答
慕码人8056858
TA贡献1803条经验 获得超6个赞
$array = (array) $object;
function toArray($obj){ if (is_object($obj)) $obj = (array)$obj; if (is_array($obj)) { $new = array(); foreach ($obj as $key => $val) { $new[$key] = toArray($val); } } else { $new = $obj; } return $new;}
- 3 回答
- 0 关注
- 901 浏览
添加回答
举报
0/150
提交
取消