title: Curl for loop writes previous loops value if there is no data in the current loop
body: <p>I am using PHP CURL to collect some data but if one of the fields in my query is empty it writes the value from the previous loop, how can I correct this so that it enters no data if the value is not set?</p>
  
  <pre><code>&lt;?php
  
      $domains = array( 'http://www.domain.com/' =&gt; '1',
                'http://www.domain2.com/'  =&gt; '2'
          );
  
      function file_get_contents_curl($url){
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_HEADER, 0);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
          $data = curl_exec($ch);
          curl_close($ch);
          return $data;
      }
  
      foreach ($domains as $url =&gt; $urlKey) {
  
      $html = file_get_contents_curl($url);
  
      $doc = new DOMDocument();
      @$doc-&gt;loadHTML($html);
      $nodes = $doc-&gt;getElementsByTagName('title');
  
      $title = $nodes-&gt;item(0)-&gt;nodeValue;
  
      $metas = $doc-&gt;getElementsByTagName('meta');
  
      for ($i = 0; $i &lt; $metas-&gt;length; $i++)
      {
          $meta = $metas-&gt;item($i);
          if($meta-&gt;getAttribute('name') == 'description') {
          $description = $meta-&gt;getAttribute('content');
          }
          if($meta-&gt;getAttribute('name') == 'keywords') {
          $keywords = $meta-&gt;getAttribute('content');
          }
      }
  
      echo "Title: " . $title . "&lt;br&gt;";   
      echo "Description: " . $description . "&lt;br&gt;";   
      echo "Keywords: " . $keywords . "&lt;br&gt;";
  </code></pre>