<?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
您只需创建一个空数组并调用该数组的某个索引而无需导入某个值就可以了... –