PHP CSV string to array

前端 未结 10 1283
攒了一身酷
攒了一身酷 2020-11-27 02:41

I\'m trying to parse a CSV string to an array in PHP. The CSV string has the following attributes:

Delimiter: ,
Encl         


        
10条回答
  •  长情又很酷
    2020-11-27 03:32

    If you need a name for the csv columns, you can use this method

     $example= array_map(function($v) {$column = str_getcsv($v, ";");return array("foo" => $column[0],"bar" => $column[1]);},file('file.csv'));
    

提交回复
热议问题