Why only one 2D array is output? & Lt ;? Php $ foodPrices & nbsp; array (vegetable & nbsp; & gt; & nbsp; array (potato & nbsp; & gt; & nbsp; 1.00, & nbsp; onion & nbsp; & gt; & nbsp ;. 50), why does the fruit & nbsp; 2-dimensional array output only one?
$foodPrices = array(
"vegetable" => array("potato" => 1.00, "onion" => .50),
"fruit" => array("apple" => 2.50, "orange" => 2.00)
);
foreach($foodPrices as $category)
{
foreach($category as $food => $price);
{
$f_price = sprintf("%01.2f", $price);
echo "$food: \$$f_price
";
}
}
?>
Output only
Onion: $0.50
Orange: $2.00
Why is one missing?
------ Solution --------------------
Foreach ($ foodPrices as $ category)
{
Foreach ($ category as $ food => $ price) // multiple semicolons in this row
{
$ F_price = sprintf ("% 01.2f", $ price );
Echo "$ food :\$ f_price ";
}
}
------ Solution --------------------
Foreach ($ category as $ food => $ price );
A semicolon is added here;
------ Solution --------------------
The second foreach is followed by a semicolon.
OK ??
------ Solution --------------------
Foreach ($ category as $ food = >$ price); <== multiple semicolons