Array, This code above, does not show any error and when I open it: [closed]

-11

link

This code above, does not present any error and when I open it:

link

    
asked by anonymous 18.05.2018 / 21:34

2 answers

2

The error pointed to refers to the variable "$ honey" that does not exist, the one you declared is "$ meal".

    
18.05.2018 / 21:37
0

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>
    
18.05.2018 / 21:52