如何在数组中使用循环

时间:2014-02-27 05:22:26

标签: php

当我使用时:

foreach ($pages['data'] as $page) {
    $page_access_token = $page['access_token'];
    $page_conversations = $facebook->api('/222222222222/conversations', 'GET', array('access_token' => $page_access_token)); 

    $SenderName = $page_conversations["data"][0]["participants"]["data"][0]["name"];
    $IDPage     = $page_conversations["data"][0]["participants"]["data"][0]["id"];

    echo $SenderName;
    echo "<br>";
    echo $IDPage;
}

我只从我的数据中得到索引[0]。

Anti Virus Indonesia
171360273518

如何循环所有数据,如:

Anti Virus Indonesia
171360273518
TelkomVision Interact
1413864677

如何从这样的数据中获取数据?

1 个答案:

答案 0 :(得分:1)

它几乎就像瞄准盲目折叠没有数据。但你可以尝试一次吗?

foreach ($pages['data'] as $page) {
    $page_access_token = $page['access_token'];
    $page_conversations = $facebook->api('/222222222222/conversations', 'GET', array('access_token' => $page_access_token)); 

    foreach ($page_conversations["data"] as $conversations) {
        $SenderName = $conversations["participants"]["data"][0]["name"];
        $IDPage     = $conversations["participants"]["data"][0]["id"];
        echo $SenderName;
        echo "<br>";
        echo $IDPage;
    }

}

或者这个

foreach ($pages['data'] as $page) {
    $page_access_token = $page['access_token'];
    $page_conversations = $facebook->api('/222222222222/conversations', 'GET', array('access_token' => $page_access_token)); 

    foreach ($page_conversations["data"][0]["participants"]["data"] as $conversations) {
        $SenderName = $conversations["name"];
        $IDPage     = $conversations["id"];
        echo $SenderName;
        echo "<br>";
        echo $IDPage;
    }

}