Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 18th, 2012  |  syntax: None  |  size: 1.45 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I exclude an object from my array so a foreach loop avoids it?
  2. {
  3.    "data": [
  4.       {
  5.          "name": "Person 1",
  6.          "id": "12345678",
  7.          "picture": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/123456789_123456_789456.jpg"
  8.       },
  9.       {
  10.          "name": "Person 2",
  11.          "id": "12345679",
  12.          "picture": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/123456789_123456_789457.jpg"
  13.       }
  14.    ],
  15.    "paging": {
  16.       "next": "https://graph.facebook.com/me/friends?access_token=.....&fields=name,id,picture&limit=5000&offset=5000&__after_id=..."
  17.    }
  18. }
  19.        
  20. $url  = "https://graph.facebook.com/". $uid ."/friends?access_token=". $access_token ."&fields=name,id,picture";
  21.         $users = json_decode(file_get_contents($url));
  22.  
  23.         echo $access_token .'<br><br>';
  24.  
  25.         foreach ($users as $name => $value) {
  26.             foreach ($value as $entry) {
  27.                 //Loop for profile pics
  28.                 if ($entry->picture) {
  29.                     echo '<a href="https://www.facebook.com/profile.php?id=' . $entry->id . '" target="_blank">' . '<img src="'. $entry->picture . '" class="profile-thumb' . $entry->name . '" id="'. $entry->id .'"></a>';
  30.                 }
  31.             }
  32.         }
  33.        
  34. Notice: Trying to get property of non-object in C:inetpubwwwrootferef.comfacebooktest-appfriends.php on line 50
  35.        
  36. $data = $users->('data');
  37.        
  38. foreach($data as $entry){
  39.     if(isset($entry->picture)){
  40.         echo ...
  41.     }
  42. }