我知道我可以在双引号中使用数组值。这样的:
<?php echo "my name is: $arr[name]"; ?>
但是当我使用多维数组时,我看不到我的结果:
<?php echo "he is $twoDimArr[family][1]"; ?>
这里的输出是:he is Array[1]
原因是什么?
我知道我可以这样使用我的代码:
<?php echo "he is ".$twoDimArr[family][1]; ?>
但是我不想这样
更复杂的结构应该用花括号括起来:
echo "he is {$twoDimArr['family'][1]}";
你应该这样做,使用花括号{
&}
:
echo "he is {$twoDimArr['family'][1]}";
详细信息请参见
String parsing
文档和echo()函数(特别是示例#1):
// You can also use arrays
$baz = array("value" => "foo");
echo "this is {$baz['value']} !"; // this is foo !
// Using single quotes will print the variable name, not the value
echo 'foo is $foo'; // foo is $foo