Friday, 26 August 2016

Printing quoted multidimensional arrays in PHP



I know in PHP you can echo variables with double-quotes, but if I try to echo a multidimensional array, it doesn't work. Like...



echo "Here's my variable: $array[0][name]";


And that outputs : "Array[name]"



Is there a way to print its value without closing the quotes?



Answer




Is there a way to print its value without closing the quotes?




Yes, using Complex (curly) syntax:



echo "Here's my variable: {$array[0]['name']}";



Demo


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...