note 33153 added to function.fgetcsv
| From: | kyle at rack1 dot php dot net | Date: | Tue, 17 Jun 2003 21:05:00 +0000 |
| Subject: | note 33153 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50531@lists.php.net to get a copy of this message | ||
Quick and dirty script to take a csv file and turn it into a multidimensional associative array
structure using the first line of the csv as the hash key names.
<?
$i = 0;
$handle = fopen ("file.csv","r");
while($data = fgetcsv ($handle, 1000, ",")) {
if ($i == 0) { $key_arr = $data; }
reset($key_arr);
while(list($index,$name) = each($key_arr)) { $temp_arr[$name] = $data[$index]; }
$result_arr[$i] = $temp_arr;
$i++;
}
fclose ($handle);
?>
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33153
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33153&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33153&report=yes