title: Why is foreach over a results object not working?
body: <p>I realize there are quite a few questions of this nature, but I have not been able to solve my issue using the other posts, so I was hoping someone here may be able to help me out.</p>
  
  <p>I have an object I'm getting back from Yahoo local search API. I have passed the results into <code>json_decode()</code> and saved the results to <code>$yahoo_json_decoded</code>. I can get data from the results using a for loop and doing the following:</p>
  
  <pre><code>echo 'Name: ' . $yahoo_json_decoded-&gt;ResultSet-&gt;Result[$i]-&gt;Title . '&lt;br /&gt;' ;
  </code></pre>
  
  <p>But I can't seem to be able to make the foreach work:</p>
  
  <pre><code>foreach($yahoo_json_decoded-&gt;ResultSet as $res=&gt;$variable)
  {
      $listingID = $yahoo_json_decoded-&gt;ResultSet[$res]-&gt;id ;
      echo $listingID;
  }
  </code></pre>
  
  <p>I could just loop the data and move on, but I really want to understand why the <code>foreach</code> isn't working.</p>
  
  <p>Thanks (show mercy)</p>
  
  <p>Kirk</p>