Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php从csv文件中选择数据列_Php_Csv - Fatal编程技术网

使用php从csv文件中选择数据列

使用php从csv文件中选择数据列,php,csv,Php,Csv,我有类似csv的文件 a, b, c, d 1, 2, 3, 4 5, 6, 7, 8 9, 10, 11, 12 我希望使用php输出如下所示 a 1 5 9 b 2 6 10 c 3 7 11 d 4 8 12 使用此功能 到目前为止,您尝试了什么代码?str_replace('、'、'$string)也许?算了吧,这充其量只是些小事。 <?php $row=str_getcsv(string); $field=array('a','b','c','d'); $n=0; whil

我有类似csv的文件

a, b, c, d
1, 2, 3, 4
5, 6, 7, 8
9, 10, 11, 12
我希望使用php输出如下所示

a 1 5 9
b 2 6 10
c 3 7 11
d 4 8 12
使用此功能


到目前为止,您尝试了什么代码?
str_replace('、'、'$string)
也许?算了吧,这充其量只是些小事。
<?php
$row=str_getcsv(string);

$field=array('a','b','c','d');
$n=0;
while($n<count($field)) { 
echo $field[$n]
foreach($row as $item){
    echo $item[$n];
    echo ' ';
}
echo '\n';
$nbfield++
}