title: How to reorder column headers from imported CSV in PHP?
body: <p>I am trying to reorder columns that are in the CSV file that I am importing in PHP. The order should be ID, Carrier, TrackingNumber, ShippingDate </p>
  
  <p>My code looks like this:</p>
  
  <pre><code> $rename = array('Customer PO#'=&gt;'ID', 'Ship Via'=&gt;'Carrier', 'Tracking Number'=&gt;'TrackingNumber', 'Ship Date'=&gt;'ShippingDate'); 
   $csv = array_map('str_getcsv', file('file.csv')); 
  
   foreach($csv[0] as $col =&gt; $colname) {
       if(!empty($rename[$colname])) $csv[0][$col] = $rename[$colname];
   }
   array_walk($csv, function(&amp;$a) use ($csv) { 
       $a = array_combine($csv[0], $a);
  
       if (array_key_exists('Product ID', $a)) {
           unset($a['Product ID']);
       }
       if (array_key_exists('Customer Name', $a)) {
           unset($a['Customer Name']);
       }
   }); 
  
  var_dump($csv);
  </code></pre>
  
  <p>My array looks like this:</p>
  
  <pre><code>  [1]=&gt;
    array(4) {
      ["ShippingDate"]=&gt;
      string(10) "11/21/2018"
      ["ID"]=&gt;
      string(5) "59098"
      ["Carrier"]=&gt;
      string(16) "USPS First Class"
      ["TrackingNumber"]=&gt;
      string(22) "940011020088289578733355"
    }
  </code></pre>