title: php api associative array
body: <p>I'm trying to loop through an api call very quickly but I'm seeing very odd behavior with the following loop (doesn't loop through the entire array....writes only 1 or 2 records):</p>
  
  <p>Any ideas:</p>
  
  <pre><code>$i = 0;
  foreach($userfriends as $key =&gt; $value) {
  
      if($key == "id"){
      $friend_id = $value;        
      }
  
      try {
      $username = $friend_id;
      $uservar = '/'.$username.'/likes?fields=id,category&amp;limit=20';
      $userlikes = $facebook-&gt;api($uservar);
      }         
  
      catch (FacebookApiException $e) {
      error_log($e);
      }
  
  
      $id = $userlikes[data][$i][id];
      $cat = $userlikes[data][$i][category];
  
  
      // WRITING FRIEND LIKES TO DATABASE
  
      $sql="INSERT INTO likes (like_id, category, friend_id) VALUES ('$id', '$cat', '$friend_id');";
      mysql_query($sql,$con);
  
  
  
  $i++;
  }
  </code></pre>
  
  <p>The array userfriends looks like this:</p>
  
  <pre><code>Array
  (
      [data] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [id] =&gt; 123123
                  )
  
              [1] =&gt; Array
                  (
                      [id] =&gt; 456456
                  )
  
              [2] =&gt; Array
                  (
                      [id] =&gt; 634476
                  )
  </code></pre>