PHP array problem.

ClutchClutch North Carolina New
edited September 2007 in Internet & Media
I've got an array that I have coded, very simple but I'm running into problems.

I want the Key and Value of the array to be inside a table. But when I view my script I get this:

breakfast %value
Lunch %value
snack %value
dinner %value

Here is my code, did I do something wrong? They keys are showing up in my table, but not the values.

[PHP]
<html>
<head><title>Dinner</title></head>
<body>
<?php
$meal = array('breakfast' => 'Walnut Bun',
'Lunch' => 'Cashew Nuts and White Mushrooms',
'snack' => 'Dried Mulberries',
'dinner' => 'Eggplant with Chili Sauce');
print "<table>\n";
foreach ($meal as $key => $value) {
print "<tr><td>$key</td><td>%value</td></tr>\n";
}
print '</table>';
?>
</body>
</html>[/PHP]

Comments

  • LincLinc Owner Detroit Icrontian
    edited September 2007
    Clutch wrote:
    Here is my code, did I do something wrong?
    Small typo :)

    In the print statement within the foreach loop, replace this:
    [php]%value[/php]With this:
    [php]$value[/php]You were off a number key is all.
  • ClutchClutch North Carolina New
    edited September 2007
    Doh!! It's always the smallest things that can throw off everything. Thanks man, I have been beating my head against that code all night.
Sign In or Register to comment.