因此,我收到了许多未定义常量的错误,而且我不确定为什么。如果有区别,我正在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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句