title: Get data from curl to put in array and display in php
body: <p>I need to get the data from a curl in php and have it display all data in that array. I can't seem to get it to work at all. I am trying a while statement but that does not seem to work. It's like it's not an array. I only need to pull out the zip_code for each place and display that zip code. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>function remote_get_contents($url)
  {
      if (function_exists('curl_get_contents') AND 
   function_exists('curl_init'))
      {
              return curl_get_contents($url);
      }
      else
      {
              return file_get_contents($url);
      }
  }
  
  function curl_get_contents($url)
  {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $output = curl_exec($ch);
      curl_close($ch);
      return $output;
  }
  
  $url = 'URL_HIDDEN';
  $object = json_decode(remote_get_contents($url));
  $url2 = 'URL_HIDDEN';
  $object2    = json_decode(remote_get_contents($url2));
  
  $zip = $object-&gt;postal;
  $city = $object-&gt;city;
  $zips = $object2-&gt;zip_code;
  
  echo $city ." | ". $zip . " | ". $zips ."&lt;br /&gt;";
  </code></pre>
  
  <p>Here is the raw data output (all I need is each zip_code to show) It could be longer or shorter. In some cases it could be 50+ zip codes that need to be pulled out. Other cases it could just be 1 or 2. </p>
  
  <pre><code> {
    "zip_codes": [
      {
          "zip_code": "27356",
          "distance": 47.395,
          "city": "Star",
          "state": "NC"
      },
      {
          "zip_code": "27247",
          "distance": 46.972,
          "city": "Ether",
          "state": "NC"
      },
      {
          "zip_code": "27325",
          "distance": 45.174,
          "city": "Robbins",
          "state": "NC"
      },
      {
          "zip_code": "27259",
          "distance": 44.428,
          "city": "Highfalls",
          "state": "NC"
      },
      {
          "zip_code": "27330",
          "distance": 49.074,
          "city": "Sanford",
          "state": "NC"
      },
      {
          "zip_code": "27341",
          "distance": 40.783,
          "city": "Seagrove",
          "state": "NC"
      },
      {
          "zip_code": "27237",
          "distance": 46.55,
          "city": "Cumnock",
          "state": "NC"
      },
      {
          "zip_code": "28137",
          "distance": 49.68,
          "city": "Richfield",
          "state": "NC"
      },
      {
          "zip_code": "27208",
          "distance": 38.639,
          "city": "Bennett",
          "state": "NC"
      },
      {
          "zip_code": "27252",
          "distance": 41.732,
          "city": "Goldston",
          "state": "NC"
      }
   ]
   }
  </code></pre>