I have a CSV file with headings in both the columns and rows that i need as an associative array and the examples i have tried on SO haven\'t worked for me.
The closest
You need a second foreach
to achieve what you want.
Something like this:
foreach ($all_rows as $row) {
if($row) {
foreach($row as $key => $val) {
if($key == "Food" && $val == "Apples") {
echo "Apples: " . "
";
echo $row["In_Stock"] . "
";
echo $row["On_order"] . "
";
}
else if($key == "Food" && $val == "Oranges") {
echo "Oranges: " . "
";
echo $row["In_Stock"] . "
";
echo $row["On_order"] . "
";
}
}
}
}
If you just want to print the values on your page, this could do it.
But I since you've mentioned to just call the values based on food type, you can create a function out of this.