PHP array problem.
Clutch
North Carolina New
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]
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]
0
Comments
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.