迭代数组并提取数据

时间:2015-06-29 02:09:39

标签: php arrays facebook-graph-api multidimensional-array

我正在尝试遍历此数组http://2of1.com/zee/ZEES%20SMS%20SERVICE.html并提取数据。

我正在使用:

foreach ($graphObject['data'] as $key => $value){
                    $string = $value->message;
                    $link = $value->actions[0]->link;
                    $pic = $value->picture;
                    $post_id = $value->id;
}

但是在我向阵列添加第二个源后,它不再起作用了。

当我尝试:

foreach ($graphObject as $key => $value){
                        $string = $value->data[0]->message;
                        $link = $value->data[0]->actions[0]->link;
                        $pic = $value->data[0]->picture;
                        $post_id = $value->data[0]->id;

我只从data [0]获得第一个条目值,并且它不会遍历所有数据。我需要的是来自数据[0]数据[1]数据[2]数据[3] ......等的数据......请帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

可能类似

foreach ($graphObject as $keyEntry => $entry){
    foreach( $entry->data as $data ) {
        echo $data->picture, "<br />\r\n";
        foreach( $data->actions as $action ) {
            echo $action->link, "<br />\r\n";