To read in the full CSV file, use this construct:
$csv = array_map("str_getcsv", file("inventory.csv"));
$header = array_shift($csv);
This separates $headerfrom a separate array from the rest of the data $csv.
If you then (seemingly?) Want a map of two fields, try:
$col1 = array_search("stock" $headers);
$col2 = array_search("mfgid", $headers);
foreach ($csv as $row) {
$map[ $row[$col1] ] = $row[$col2]; }
This will give you an array stock→ mfgid.
mario source
share