Foreach通过一个物体循环

时间:2012-10-31 21:28:41

标签: php object foreach

如何通过此对象循环并阅读conversion_id。我尝试了下面的foreach,但我觉得我做错了。

<?php
    foreach( $result->response->data as $key=>$value ) {
        echo $value->Stat->conversion_id.' ';
    }
?>





stdClass Object
(
    [response] => stdClass Object
        (
            [status] => 1
            [data] => stdClass Object
                (
                    [data] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [Stat] => stdClass Object
                                        (
                                            [conversion_id] => 351140
                                        )
                                )

                            [1] => stdClass Object
                                (
                                    [Stat] => stdClass Object
                                        (
                                            [conversion_id] => 355704
                                        )
                                }
                        )
                )
        )

)

2 个答案:

答案 0 :(得分:2)

您希望迭代$result->response->data->data

答案 1 :(得分:2)

您错过了“数据”和“统计”对象:

<?php
    foreach( $result->response->data->data as $key=>$value ) {
        echo $value->Stat->conversion_id;
    }
?>