note 75672 deleted from function.fgetcsv by cmb
| From: | cmb@php.net | Date: | Sun, 16 Jun 2019 08:06:16 +0000 |
| Subject: | note 75672 deleted from function.fgetcsv by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211261@lists.php.net to get a copy of this message | ||
Note Submitter: D Steer
----
Here is a simple to include the field names in the array. Altough this is very simple, it does the
job fantastically
<?php
print_r(buildStock('stock.csv'));
function buildStock($File) {
$handle = fopen($File, "r");
$fields = fgetcsv($handle, 1000, ",");
while($data = fgetcsv($handle, 1000, ",")) {
$detail[] = $data;
}
$x = 0;
$y = 0;
foreach($detail as $i) {
foreach($fields as $z) {
$stock[$x][$z] = $i[$y];
$y++;
}
$y = 0;
$x++;
}
return $stock;
}
?>