所以我得到了一堆未定义常量的错误,我不知道为什么。如果有区别的话,我在Windows WAMP服务器上运行。我正在dreamweaver CS6中编写代码,它没有显示任何错误。这是代码:
<!DOCTYPE html>
<?php
$services = Array(
"website" => array (
title => "Web Site Design",
price => "Vaires Contact us for a Free Quote",
blurb => "We make good websites"
),
"nas" => array (
title => "NAS Storage",
price => "Vaires Contact us for a Free Quote",
blurb =>" We make make good servers"
),
"localserver" => array (
title => "Local Sever Setup",
price => "Vaires Contact us for a Free Quote",
blurb => "We make make good servers"
),
);
?>
<html>
<head>
<meta charset="utf-8">
<?php include 'includes/header.php'?>
<title>Anise Technologys | Services</title>
</head>
<body>
<div class="wrapper">
<?php include 'includes/nav.php'?>
<div class="content">
<h1 id="title-center">Services</h1>
As a business technology solution we offer a wide range of solutions to fit your business's needs
<div class="list">
<?php foreach ($services as $key => $item) {?>
<div class="list-left"><?php echo $item[title]; ?></div>
<div class="list-mid"><?php echo $item[blurb]; ?></div>
<div class="list-right"><a href="http://localhost/latech/service?item=<?php echo $key; ?>">More</a></div>
<hr>
<?php } ?>
</div>
</div>
</div>
</body>
</html>
数组的键值是字符串,应该作为引用
$services = Array(
"website" => array (
'title' => "Web Site Design",
'price' => "Vaires Contact us for a Free Quote",
'blurb' => "We make good websites"
),
"nas" => array (
'title' => "NAS Storage",
'price' => "Vaires Contact us for a Free Quote",
'blurb' =>" We make make good servers"
),
"localserver" => array (
'title' => "Local Sever Setup",
'price' => "Vaires Contact us for a Free Quote",
'blurb' => "We make make good servers"
),
);
PHP将未引用的字符串值视为常量,它将检查是否存在具有该名称的常量,如果存在,则替换其值。
如果不存在该名称的常量,那么它将(慷慨地)假设您打算使用带引号的字符串,并将其视为带引号的字符;但它会发出通知,让你知道你应该修复它。
请注意,在检查常量列表和发出通知时都会有性能开销,因此修复对您有利
还请注意,当您在代码中引用该数组时,同样的情况也适用,因此
<div class="list-left"><?php echo $item[title]; ?></div>
<div class="list-mid"><?php echo $item[blurb]; ?></div>
应该是
<div class="list-left"><?php echo $item['title']; ?></div>
<div class="list-mid"><?php echo $item['blurb']; ?></div>