Re: Need function to process tab delimited file using associative array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- Original Message ----- 
From: "Justin French">
> The disadvantage is that you have to loop through the data twice (once
> as a tab-delimited file, once as an assoc. array), which would have
> obvious problems when there's a large set of data that needs to be
> looped through often.

> Justin French

Justin,
Your fgetcsv() function was what I was needing. I found this in it notes:

<snip_from_fgetcsv>
 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);
?>
</snip_from_fgetcsv>


Thanks!
-eric wood

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux