<?php
define("TITLE", "Menu Item | Risque");
include('includes/header.php');
$menuItem = '';
$dish = '';
if (isset($_GET['item'])) {
$menuItem = $_GET['item'];
$dish = $menuItems[$menuItem];
}
function suggestedTip ($price, $tip){
$totalTip = $price * $tip;
}
?>
<center><img src = "hr.png">
<br>
<div id = "dish">
<h1><?php $dish = array(); echo $dish["title"]; ?> <span class="price"><sup>$</sup><?php echo $dish["price"]; ?></span></h1>
<p><?php echo $dish["blurb"]; ?></p>
<br>
<p><strong>Suggested beverage: <?php echo $dish["drink"]; ?></strong></p>
<p><em>Suggested tip: <sup>$</sup><?php suggestedTip($dish["price"], 0.20); ?></em></p>
</div>
arrays.php代碼如下所示 莫名其妙的數組中的值不會在我的網頁顯示未定義的索引數組不能引用我的其他PHP頁面?
<?php
$navItems = array (
array(
'slug' => "index.php",
'title' => "Home"
),
array(
'slug' => "menu.php",
'title' => "Menu"
),
array(
'slug' => "contact.php",
'title' => "Contact"
),
);
$menuItems = array(
"club-sandwich" => array(
"name" => "Club Sandwich",
"price" => 11,
"blurb" => "Bacon ipsum dolor sit amet fatback landjaeger ullamco pariatur. Nostrud laboris et, duis drumstick eiusmod kevin ut aliquip. Filet mignon short ribs tenderloin short loin kielbasa non pork chop aliqua. Jerky shank tri-tip capicola, non andouille tenderloin cupidatat turducken meatball pork beef eu shoulder jowl.",
"drink" => "Club Soda"
),
"dill-salmon" => array(
"name" => "Lemon & Dill Salmon",
"price" => 18,
"blurb" => "Pork belly tempor ground round qui exercitation, jowl leberkas sed voluptate excepteur jerky. Reprehenderit veniam cow, quis in ribeye andouille eu pastrami eiusmod exercitation dolor.",
"drink" => "Fancy Wine"
),
"super-salad" => array(
"name" => "The Super Salad<sup>®</sup>",
"price" => 34,
"blurb" => "Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.",
"drink" => "Jug o' Water"
),
"mexican-barbacoa" => array(
"name" => "Mexican Barbacoa",
"price" => 23,
"blurb" => "I love fruitcake danish caramels. Tart danish pastry liquorice chocolate cake fruitcake. Bear claw gingerbread muffin I love apple pie apple pie tiramisu brownie chocolate. Sweet roll cotton candy cupcake gingerbread gummies jelly-o. Muffin I love croissant I love jelly-o brownie jelly beans. Toffee I love pastry.",
"drink" => "Beer with a lime"
),
);
?>
我是新來的PHP,但我有一個項目,是因爲很快就會發生,但是我一直收到title
,price
和blurb
的未定義錯誤。
如果有人能幫到,我將不勝感激。
你在哪裏填充$ dish [「title」]? –
我應該告訴你整個代碼嗎? – Jinn
您只需創建一個空數組並調用該數組的某個索引而無需導入某個值就可以了... –