Process CSV Into Array With Column Headings For Key

后端 未结 9 2521
星月不相逢
星月不相逢 2020-11-29 03:35

I have a CSV with the first row containing the field names. Example data is...

\"Make\",\"Model\",\"Note\"
\"Chevy\",\"1500\",\"loaded\"
\"Chevy\",\"2500\",         


        
9条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 03:58

    $all_rows = array();
    $header = fgetcsv($file);
    while ($row = fgetcsv($file)) {
      $all_rows[] = array_combine($header, $row);
    }
    
    print_r($all_rows);
    

提交回复
热议问题