我有详细信息.csv与以下内容:
name,phone,address
john,123,abc
suse,134,bca
字符串
我想插入空的新列,因此它将变为:
name,phone,city,postcode,address
john,123,"","",abc
suse,134,"","",bca
型
或者变成这样(以更容易的为准)
name,phone,city,postcode,address
john,123,city,postcode,abc
suse,134,city,postcode,bca
型
是的
<?php
$filename = 'details.csv';
$the_big_array = [];
if (($h = fopen("{$filename}", "r")) !== FALSE)
{
while (($data = fgetcsv($h, 1000, ",")) !== FALSE)
{
$data[] = 'city';
$data[] = 'postcode';
$the_big_array[] = $data;
}
fclose($h);
}
echo "<pre>";
var_dump($the_big_array);
echo "</pre>";
?>
型
但我得到了这个:
name,phone,address,city,postcode
john,123,abc,city,postcode
suse,134,bca,city,postcode
型
救命啊...
1条答案
按热度按时间hk8txs481#
可以使用
array_splice()
https://www.php.net/manual/en/function.array-splice.php
字符串