Array , This code above is no mistake and when I open it :

Asked

Viewed 66 times

-11

  • 4

    Post codes, not prints

  • 1

    If there was no mistake, it would not show errors.

2 answers

2

The error pointed refers to the variable "$mel" that does not exist, which you declared is "$Meal".

  • That’s right the use of the declared variable is wrong.

0

Detail, in addition to the typing error of the variable, as already mentioned the Valdir Silva, it seems that these foreach are changes... Because you define, for example, the variable $dish in the second foreach, but uses it in the first (?). Try trade in of place the foreach.. I think it works...

Another detail, the variable $price and $value are switched, invert them as well. And the variable should 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.