2014-02-27 70 views
-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)); 

    $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 

我如何從這樣的數據中的數據?

+0

您沒有正確粘貼鏈接到您的數據。 –

+0

可以將數據粘貼到pastebin中 – SajithNair

回答

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; 
    } 

} 
+0

謝謝....其作品 –