如何将对象转换为数组?
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
    )...
)
这可能吗?
回答:
您应该查看get_object_vars,因为您的属性被声明为私有,所以您应该在类内部调用此方法并返回其结果。
注意,对于像字符串这样的原始数据类型,它会很好用,但是我不知道它在嵌套对象中的行为。
在您的情况下,您必须执行类似操作;
<?php   print_r(get_object_vars($response->response->docs));
?>
以上是 如何将对象转换为数组? 的全部内容, 来源链接: utcz.com/qa/419922.html






