Majid Sadr Majid Sadr - 5 months ago 9
PHP Question

PHP - Multidimensional arrays can`t be in double quotations

I know I can use an array value in double quotation. Like this:

<?php echo "my name is: $arr[name]"; ?>


But when I use Multidimensional array, I can`t see my result:

<?php echo "he is $twoDimArr[family][1]"; ?>


Here, the output is: he is Array[1]

What`s the reason?

And I know I can use my code like this:

<?php echo "he is ".$twoDimArr[family][1]; ?>


But I don't want this.

Answer

You should enclose more complicated structures in curly braces:

echo "he is {$twoDimArr['family'][1]}";
Comments