title: PHP: How to Parse JSON From API call?
body: <p>I have a CURL response that looks like this:</p>
  
  <pre><code>{"page_number":2,"items":[],"items_per_page":1,"kind":"search#companies","total_results":0,"start_index":1} 
  </code></pre>
  
  <p>All i need from that is the value of <code>"total_results":0</code></p>
  
  <p>so I am trying to get <code>"total_results"</code> like this:</p>
  
  <pre><code>$url = "https://api.companieshouse.gov.uk/search/companies?q=POOdfgdfgyygfhfgfgfghgfP&amp;items_per_page=1&amp;start_index=0";
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_USERPWD, "my_password");
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  
  $output = curl_exec($ch);
  $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  $info = curl_getinfo($ch);
  curl_close($ch);
  
  echo $output-&gt;total_results[0];
  </code></pre>
  
  <p>However, when I echo the <code>$output-&gt;total_results[0];</code>, I get nothing being echoed on my page. So i don't really know what I am doing wrong!</p>
  
  <p>Could someone please advise on this issue?</p>
  
  <p>any help would be appreciated.</p>