title: Using array_combine to store data read from csv
body: <p>From a csv file I need to extract the header and the values. Both are later accessed in frontend.</p>
  
  <pre><code>$header = array();
  $contacts = array();
  
  if ($request-&gt;isMethod('POST')) {
  
     if (($handle = fopen($_FILES['file']['tmp_name'], "r")) !== FALSE) {
          $header = fgetcsv($handle, 1000, ",");
  
          while (($values = fgetcsv($handle, 1000, ",")) !== FALSE) {
  
              // array_combine
              // Creates an array by using one array for keys
              // and another for its values
              $contacts[] = array_combine($header, $values);
          }
          fclose($handle);
     }
  } 
  </code></pre>
  
  <p>It works with csv files that look like this</p>
  
  <pre><code>Name,Firstname,Organisation,
  Bar,Foo,SO,
  </code></pre>
  
  <p>I just exported my gmail contacts and tried to read them using the above code but I get following error</p>
  
  <blockquote>
    <p>Warning: array_combine() [function.array-combine]: Both
    parameters should have an equal number of elements</p>
  </blockquote>
  
  <p>The gmail csv looks like this</p>
  
  <pre><code>Name,Firstname,Organisation
  Bar,Foo,SO
  </code></pre>
  
  <p>Is the last missing <code>,</code> the reason for the error? What is wrong and how to fix it?</p>
  
  <p>I found this on SO</p>
  
  <pre><code>function array_combine2($arr1, $arr2) {
      $count = min(count($arr1), count($arr2));
      return array_combine(array_slice($arr1, 0, $count),
                           array_slice($arr2, 0, $count));
  }
  </code></pre>
  
  <p>This works but it skips the <strong>Name</strong> field and not all fields are combined. Is this because the gmail csv is not realy valid? Any suggestions?</p>