0

I have a facebook array and I am trying to echo out the names and ID.

All I have is this array: $friends_list.

When I use this code:

print_r($friends_list);

Then the following comes out below: But how do I loop thru these? Or what if I just wanted to find out how many names there are or just call on one var by id. In short how do I echo out $friends_list which is a multiD array?

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 ) ) 
Papa De Beau
  • 3,744
  • 18
  • 79
  • 137

1 Answers1

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
Community
  • 1
  • 1
Grmn
  • 542
  • 2
  • 9
  • 1
    show us what you got!, so we can help YOU, with YOUR code! also have a look at the url posted by Marc B, and see this for counting http://php.net/manual/en/function.array-count-values.php – Grmn Apr 05 '13 at 21:44
  • this is all I have: $friends_list = $facebook->api('/1566027944/friends'); - - Gives me a multidimensional array. I don't know how to get to the vars other than print_r($friends_list); but that won't let me get to the ID or NAME – Papa De Beau Apr 05 '13 at 22:01
  • 1
    Take a look and see if this is what you want http://stackoverflow.com/questions/3835028/getting-list-of-facebook-friends-with-latest-api – Grmn Apr 05 '13 at 22:04
  • This last link did it. Awesome! :) – Papa De Beau Apr 05 '13 at 22:21
  • foreach ($friends["data"] as $value) { echo '
  • '; echo '
    '; echo ''; echo '
    '; echo '
    '.$value["name"].'
    '; echo '
  • '; } – Papa De Beau Apr 05 '13 at 22:22
  • Post the answer and I will delete this comment and give you credit – Papa De Beau Apr 05 '13 at 22:22
  • Glad we were able to help you solve it, no need for me to post it as answer, basicly it was already answered by another use at the last link! – Grmn Apr 05 '13 at 22:24