这是我的代码:
<?php
$contacts = array($alena = array("name" => "Alena Holligan",
"email" => "alena.holligan@teamtreehouse.com"),
$dave = array("name" => "Dave McFarland",
"email" => "dave.mcfarland@teamtreehouse.com"),
$treasure = array("name" => "Treasure Porth",
"email" => "treasure.porth@teamtreehouse.com"),
$andrew = array("name" => "Andrew Chalkley",
"email" => "andrew.chalkley@teamtreehouse.com")
);
echo "<ul>\n";
names.
echo "<li>$contacts[0][name]</li>\n";
echo "</ul>\n";
?>
当我尝试查看运行此脚本的网页时出现此错误:
Notice: Array to string conversion in index.php on line 15
Array[name]
是否有内置函数将此数组转换为字符串,或者我是否有语法错误?
这是针对teamtreehouse.com的,所以我想我错过了一些简单的东西。
答案 0 :(得分:-1)
尝试以下代码:
<?php echo $contacts[$alena]['name']; ?>
问题是你没有创建任何数组键是命名为“0”