ConFoo Montreal 2026: Call for Papers

Voting

: two plus four?
(Example: nine)

The Note You're Voting On

jonathangrice at yahoo dot com
15 years ago
This is how to read a csv file into a multidimensional array.

<?php
# Open the File.
if (($handle = fopen("file.csv", "r")) !== FALSE) {
# Set the parent multidimensional array key to 0.
$nn = 0;
while ((
$data = fgetcsv($handle, 1000, ",")) !== FALSE) {
# Count the total keys in the row.
$c = count($data);
# Populate the multidimensional array.
for ($x=0;$x<$c;$x++)
{
$csvarray[$nn][$x] = $data[$x];
}
$nn++;
}
# Close the File.
fclose($handle);
}
# Print the contents of the multidimensional array.
print_r($csvarray);
?>

<< Back to user notes page

To Top