这是我的代码:
<?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,所以我想我遗漏了一些简单的东西。
试试下面的代码:
<?php echo $contacts[$alena]['name']; ?>
问题是你没有创建任何数组键命名为"0"