PDA

View Full Version : PHP array problem.


Clutch
22 Sep 2007, 04:47am
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.


<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>

Keebler
22 Sep 2007, 07:15am
Here is my code, did I do something wrong?
Small typo :)

In the print statement within the foreach loop, replace this:
%valueWith this:
$valueYou were off a number key is all.

Clutch
22 Sep 2007, 12:19pm
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.