title: How to get data from an array inside json data php
body: <p>I have the following array of json data. When I try to loop using a for each, php gives me the error "Object of class stdClass could not be converted to string". I want to access the nameserver in the authns array, and the soa array. How do I go about doing that? </p>
  
  <pre><code>stdClass Object ( 
      [error] =&gt; 
      [domain] =&gt; whoisdoma.net 
      [ip_address] =&gt; 108.162.199.120   
      [authns] =&gt; stdClass Object ( 
          [nameserver] =&gt; uma.ns.cloudflare.com 
          [ip] =&gt; 173.245.58.146 
          [location] =&gt; San Francisco 
      ) 
      [soa] =&gt; stdClass Object ( 
          [nameserver] =&gt; tom.ns.cloudflare.com 
          [email] =&gt; dns.cloudflare.com 
          [serial] =&gt; 2015505396 
          [refresh] =&gt; 10000 
          [retry] =&gt; 2400 
          [expiry] =&gt; 604800 
          [minimum] =&gt; 3600 
      )
  ) 
  </code></pre>
  
  <p>This is the code I'm using to get the data:</p>
  
  <pre><code> &lt;?php
   $domain = $_GET['domain'];
  //set the url
  $url = "http://api.site.ga/v1/dns/lookup?domain=".$domain;
  
  //start a curl session
  $ch = curl_init();
  $timeout = 5;
  
  //set curl options
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  
  //get the data
  $data = curl_exec($ch);
  
  //decode the data
  $jsonData = json_decode($data);
  
  //close the curl session
  curl_close($ch);
  
  ?&gt;
  </code></pre>
  
  <p>This is the for each loop I'm using</p>
  
  <pre><code>&lt;?php 
  
  foreach($jsonData-&gt;authns as $authns)
  {
      echo $authns-&gt;nameserver;
  }
  
  ?&gt;
  </code></pre>