2
我有一个包含一些关键字的关联数组,例如([0-50]
,[50-100]
)以及它们各自的值,如23
,443
。想要将关联数组数据转换为CSV格式
我想要生成一个CSV格式的文件,我想在其中有两列,如Distance
和Trips
。并且数组中的键必须位于Distance
的列中,并且数组中的值必须位于Trips
的列中。
我试过这个使用fputcsv()
但它没有正确响应。
<?php
$file = fopen("/tmp/abc.csv", 'w');
fputcsv($file, array(
'Distance', 'Trips'
));
foreach($ed as $k=>$v) {
fputcsv($file, $v);
}
fclose($file);
$ ed回应是这样的。
Array ( [0-50] => 880 [50-100] => 5 [100-150] => 1 [550-600] => 1 )
你能告诉你试过吗? – Will
$ file = fopen(“/ tmp/abc.csv”,'w'); fflcsv($ file,array('Distance','Trips')); foreach($ ed as $ k => $ v) { fputcsv($ file,$ v); } fclose($ file);其中$ ed是数组形式 - > Array([0-50] => 21 [50-100] => 45) –
请将$ ed添加到您的示例中 – Gavriel