You want fgetcsv
it will get each row of the CSV file as an array. Since you want to have each column into its own array, you can extract elements from that array and add it to new array(s) representing columns. Something like:
$col1 = array();
while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
$col1[] = $row[0];
}
Alternatively, you can read the entire CSV file using fgetcsv
into a 2D matrix (provided the CSV file is not too big) as:
$matrix = array();
while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
$matrix[] = $row;
}
and then extract the columns you want into their own arrays as:
$col1 = array();
for($i=0;$i<count($matrix);$i++) {
$col1[] = $matrix[0][i];
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…