Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put multidimensional arrays double quoted strings?

Tags:

arrays

string

php

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.

like image 249
Majid Sadr Avatar asked Jun 27 '16 12:06

Majid Sadr


1 Answers

You should enclose more complicated structures in curly braces:

echo "he is {$twoDimArr['family'][1]}";
like image 50
wazelin Avatar answered Oct 13 '22 04:10

wazelin