PHP reading csv column into array

后端 未结 4 402
暖寄归人
暖寄归人 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:36

    $csv = array_map("str_getcsv", file("data.csv", "r")); 
    $header = array_shift($csv); 
    // Seperate the header from data
    
    $col = array_search("Value", $header); 
     foreach ($csv as $row) {      
     $array[] = $row[$col]; 
    }
    

提交回复
热议问题