【问题标题】:PHP echo out multidimensional array from facebook varPHP从facebook var中回显出多维数组
【发布时间】:2013-04-05 21:15:31
【问题描述】:

我有一个 facebook 数组,我正在尝试呼出名称和 ID。

我只有这个数组:$friends_list。

当我使用这段代码时:

print_r($friends_list);

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

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 ) ) 

【问题讨论】:

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


【解决方案1】:

复制 --> 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

【讨论】:

  • 向我们展示你得到了什么!这样我们就可以用你的代码帮助你!还可以查看 Marc B 发布的 url,并查看此以计算 php.net/manual/en/function.array-count-values.php
  • 这就是我所拥有的:$friends_list = $facebook->api('/1566027944/friends'); - - 给了我一个多维数组。我不知道如何访问 print_r($friends_list); 以外的变量。但这不会让我找到 ID 或 NAME
  • 看看这是不是你想要的stackoverflow.com/questions/3835028/…
  • 最后一个链接做到了。惊人的! :)
  • foreach ($friends["data"] as $value) { echo '
  • ';回声'
    '; echo 'graph.facebook.com' . $value["id"] . '/picture"/>';回声'
    '; echo '
    '.$value["name"].'
    ';回声'
  • '; }
猜你喜欢
相关资源
最近更新 更多
热门标签