title: Twitter Trends API weekly.json causing error "Cannot use object of type stdClass as array"
body: <p>I have the following PHP code:</p>
  
  <pre><code>        $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$URL);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          $result = curl_exec($ch);
          curl_close($ch);
          $obj = json_decode($result);
  
          foreach ($obj[0]-&gt;trends as $trend) echo utf8_decode($trend-&gt;name);
  </code></pre>
  
  <p>which works fine for URL #1 (into the variable $URL):</p>
  
  <p><a href="http://api.twitter.com/1/trends/1.json?exclude=hashtags" rel="nofollow">http://api.twitter.com/1/trends/1.json?exclude=hashtags</a></p>
  
  <p>but causes an error "Cannot use object of type stdClass as array" for URL #2:
  <a href="http://api.twitter.com/1/trends/weekly.json?exclude=hashtags" rel="nofollow">http://api.twitter.com/1/trends/weekly.json?exclude=hashtags</a></p>
  
  <p>I have searched for a while, but can't figure out a code to fix this and handle both URLs.</p>
  
  <p>Any help would be much appreciated.</p>