PHP从facebook var中回显出多维数组

时间:2013-04-05 21:15:32

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

我有一个facebook数组,我试图回应出名字和ID。

我只有这个数组:$ friends_list。

当我使用此代码时:

的print_r($ friends_list);

然后出现以下内容:但我如何通过这些循环?或者如果我只是想知道有多少名称或只是通过id调用一个var。简而言之,我如何回显$ friends_list这是一个multiD数组?

Array ( [data] => Array ( [0] => Array ( [name] => Wendy Cukierski [id] => 524320383 ) [1] => Array ( [name] => Leticia Mercado Correa [id] => 537763225 ) [2] => Array ( [name] => Olivia Urbina [id] => 538711855 ) [3] => Array ( [name] => Ruth Albrecht [id] => 541610111 ) [4] => Array ( [name] => Josh Brahm [id] => 577546485 ) [5] => Array ( [name] => Kim Yu [id] => 583515871 ) [6] => Array ( [name] => SisterTracey Dugas [id] => 643567171 ) [97] => Array ( [name] => Mary Martinez [id] => 100004696266210 ) ) [paging] => Array ( [next] => https://graph.facebook.com/1566027944/friends?limit=5000&offset=5000&__after_id=100004696266210 ) ) 

1 个答案:

答案 0 :(得分:0)

DUPLICATE - > How to store a Facebook user's friends list in MySQL using PHP?

$friends_list = file_get_contents('https://graph.facebook.com/me/friends?access_token=' . $atoken );
    $friends_list_array  = json_decode($friends_list,true);
    $arr= $friends_list_array['data'];
    $friend_ids_arr = array();
    foreach($arr as $friend) {
        $friend_ids_arr[] = $friend['id'];
    }
    $friend_ids = implode("," , $friend_ids_arr);
    echo $friend_ids; // output: id1,id2,id3...etc