This code above, does not present any error and when I open it:
The error pointed to refers to the variable "$ honey" that does not exist, the one you declared is "$ meal".
Detail, in addition to the variable typing error, as already mentioned the Valdir Silva , it seems that these foreach
are changed s ... For you define, for example, the variable $dish
in the second foreach
, but use it in the first (?). Try change instead of foreach
.. I think it works ...
Another detail, the variable $price
and $value
are changed, invert them as well. And the variable must be $meals
and not $meal
.
It's working, you can take the test:
<!doctype html>
<html>
<head>
<title> Loop with Foreach()</title>
<meta charset="utf-8">
</head>
<body>
<?php
$meals = array('Walnut bun' => 1,
'Cashew Nuts and White Mushroons' => 4.95,
'Dried Mulberries' =>3.00,
'Eggplant with Chili Sauce' => 6.50
);
foreach ($meals as $dish => $value){
$meals[$dish] = $meals[$dish]*2;
};
foreach ($meals as $key => $price){
printf("The new price of %s is \$%.2f\n", $dish, $price);
echo "<br>";
}
?>
</body>
</html>