PHP reading csv column into array

后端 未结 4 493
暖寄归人
暖寄归人 2021-01-12 18:52

I there a php function that enables me to read a csv column (COLUMN NOT LINE) into an array or a string ?

thank you in advance.

4条回答
  •  甜味超标
    2021-01-12 19:29

    $arr=array();
    $row = -1;
    if (($handle = fopen("test.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $num = count($data);
    
            $row++;
            for ($c = 0; $c < $num; $c++) {
                $arr[$row][$c]= $data[$c];
            }
        }
        fclose($handle);
    }
    

提交回复
热议问题