Anleitung:
Code: Select all
/*
* Below is an array of cakes and information about them.
* Please write a script that generates the following html snippet
*
* [list]
* [*]Wedding Cake
Flavour: hopes and dreams
* [*]Chocolate Gateau
Flavour: chocolate
* [*]Black Forest Gateau
Flavour: fruity
* [*]Victoria Sponge
Flavour: vanilla
* [*]Tottenham Cake
Flavour: strawberry
* [/list]
*
* (html or xhtml
/
is fine!)
* Note that the list is ordered in descending order of price.
*/
Code: Select all
$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
)
);
Code: Select all
function cakeList($cakes) {
echo "[list]";
foreach($cakes as $value) {
if (is_array($value))
cakeList($value);
else
echo '[*]' . $value . '';
}
echo "[/list]";
}
echo cakeList($cakes);