title: A PHP count of the number of items returned in JSON request?
body: <p>I am looking for a way to count the number of items (in PHP) returned in these JSON strings I am getting when searching a database.</p>
  
  <p>Forgive me because I'm utterly crap at all of this.</p>
  
  <p>I was told because there is no count returned in the JSON version, like there is in the XML one from this database, I would have to use a loop to count the number of results?</p>
  
  <p>I've had a look around but nothing seems to fit what I want to do...</p>
  
  <p>The following is an example of the strings I get:</p>
  
  <pre><code>Array ( 
    [0] =&gt; stdClass Object ( 
      [score] =&gt; 12
      [popularity] =&gt; 3
      [name] =&gt; Samantha Dark
      [id] =&gt; 151019
      [biography] =&gt; [url] =&gt; http://www.themoviedb.org/person/151019
      [profile] =&gt; Array ( )
      [version] =&gt; 16
      [last_modified_at] =&gt; 2011-04-11 17:17:33
    )
  
    [1] =&gt; stdClass Object (
      [score] =&gt; 11
      [popularity] =&gt; 3
      [name] =&gt; Johnny Dark
      [id] =&gt; 158737
      [biography] =&gt; [url] =&gt; http://www.themoviedb.org/person/158737
      [profile] =&gt; Array ( )
      [version] =&gt; 14
      [last_modified_at] =&gt; 2011-04-11 17:18:38
    )
  )
  </code></pre>
  
  <p>and if applicable, here's the php I use to request &amp; decipher it</p>
  
  <pre><code>$name = $_GET['search'];
  $persons_result = $tmdb-&gt;searchPerson($name);
  $persons = json_decode($persons_result);
  
  foreach ($persons as $person) {
    echo '&lt;a href="tmdb_person.php?id='.$person-&gt;id.'"&gt;'.$person-&gt;name.'&lt;/a&gt;&lt;/br&gt;';
  }
  </code></pre>