Drucken Sie ein 2D-Array als formatierte HTML-Listenelemente, sortiert nach einem SpaltenwertPhp

PHP-Programmierer chatten hier
Guest
 Drucken Sie ein 2D-Array als formatierte HTML-Listenelemente, sortiert nach einem Spaltenwert

Post by Guest »

Einer meiner Tutoren hat mir das gegeben, aber ich stecke beim Vervollständigen etwas fest. Ich habe viele Methoden satt, aber ich weiß nicht, wie ich die Daten richtig anzeigen kann.
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.
*/
Eingabedaten:

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
)
);
Mein Code:

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);
Sie möchten, dass ich eine Liste in HTML erstelle, um die Daten in den Kommentaren anzuzeigen. Irgendwelche Ideen oder Ratschläge?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post