我有一个CSV文件看起来像这样:转换CSV到数组
Did,status
"123","Active"
"456","Not-Active"
"789","Active"
....and so on
我希望能够将其转换成一个数组,看起来像这样:
$DidStatus = array("123"=>"Active", "456"=>"Not-Active", "789"=>"Active");
我试过,但它不是我要找:
$file = file_get_contents("test.csv");
$data = array_map("str_getcsv", preg_split('/\r*\n+|\r+/', $file));
print_r($data);
但输出不TH Ë一个我在寻找:
Array
(
[0] => Array
(
[0] => Did
[1] => status
)
[1] => Array
(
[0] => 123
[1] => Active
)
[2] => Array
(
[0] => 456
[1] => Not-Active
)
[3] => Array
(
[0] => 789
[1] => Active
)
[4] => Array
(
[0] =>
)
)
你尝试过这么远吗?你卡在哪里? –
[如何使用PHP和fgetcsv函数从CSV文件创建数组](https://stackoverflow.com/questions/1269562/how-to-create-an-array-from-a-csv- file-using-php-and-the-fgetcsv-function) –
你看过http://php.net/manual/en/function.fgetcsv.php – IncredibleHat