title: Using Curl in Php to get Json STD Class Object Data
body: <p>I use the curl code below to get and display json file contents and everything works fine with the code below</p>
  
  <p>when I print the json result with </p>
  
  <pre><code>$json = json_decode($response);
   print_r($json);
  </code></pre>
  
  <p>Am having the result displayed in this format</p>
  
  <pre><code>stdClass Object ( [id] =&gt; 123
  [food] =&gt; Array ( [0] =&gt; rice ) 
  
  [buyer] =&gt; AkwaezeOby 
  
  [amount] =&gt; 2000 ) 
  </code></pre>
  
  <p>Now am trying to get values for food and buyer only and I have tried  this below but cannot get it to work</p>
  
  <pre><code>print_r($json["food"][0]);
  print_r($json["buyer"]);
  
  or
  
  echo $json["food"][0];
  echo $json["buyer"];
  </code></pre>
  
  <p>Below is the working code for data display. can someone help me to get values for <strong>food</strong> and <strong>buyer</strong> only. thanks</p>
  
  <pre><code>$curl = curl_init();
  
  curl_setopt_array($curl, array( 
  CURLOPT_URL =&gt; "myapi.com", 
  CURLOPT_RETURNTRANSFER =&gt; true, 
  CURLOPT_ENCODING =&gt; "", 
  CURLOPT_MAXREDIRS =&gt; 10, 
  CURLOPT_TIMEOUT =&gt; 30, 
  CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1, 
  CURLOPT_CUSTOMREQUEST =&gt; "GET", 
  //CURLOPT_POSTFIELDS =&gt; "$data", 
  CURLOPT_HTTPHEADER =&gt; array( 
  "accept: application/json", 
  "authorization: --my number goes here--", 
  "content-type: application/json; charset=utf-8" 
  ), 
  ));
  
  $response = curl_exec($curl); 
  $err = curl_error($curl);
  
  curl_close($curl);
  
  
   $json = json_decode($response);
  
  print_r($json);
  </code></pre>