So I've been given this by a tutor of mine, to complete I'm slightly stuck. Ive tired loads of methods but not get the right way of displaying the data.
Instructions:
/*
* Below is an array of cakes and information about them.
* Please write a script that generates the following html snippet
*
* <ul>
* <li>Wedding Cake<br />Flavour: hopes and dreams</li>
* <li>Chocolate Gateau<br />Flavour: chocolate</li>
* <li>Black Forest Gateau<br />Flavour: fruity</li>
* <li>Victoria Sponge<br />Flavour: vanilla</li>
* <li>Tottenham Cake<br />Flavour: strawberry</li>
* </ul>
*
* (html or xhtml <br> / <br /> is fine!)
* Note that the list is ordered in descending order of price.
*/
Input data:
$cakes = array(
"chocolate_gateau" => array(
"flavour" => "chocolate",
"price" => 3.50
),
"victoria_sponge" => array(
"flavour" => "vanilla",
"price" => 1.50
),
"black_forest_gateau" => array(
"flavour" => "fruity",
"price" => 2.20
),
"tottenham_cake" => array(
"flavour" => "strawberry",
"price" => 0.58
),
"wedding_cake" => array(
"flavour" => "hopes and dreams",
"price" => 5.23
)
);
My code:
function cakeList($cakes) {
echo "<ul>";
foreach($cakes as $value) {
if (is_array($value))
cakeList($value);
else
echo '<li>' . $value . '</li>';
}
echo "</ul>";
}
echo cakeList($cakes);
They want me to produce a list within html, to display the data within the comments. Any ideas or advice?
loads of methodsis a little too specific. Could you try to explain even less what you have tried and where you are stuck ?