As another add-on, {}
notation is REQUIRED if you want to use a multi-dimensional array or object inside a "
-quoted string. e.g.
$foo[1][2] = 'bar';
echo "hi $foo[1][2] mom"; // prints: hi Array[2] mom
echo "hi {$foo[1][2]} mom"; // prints: hi bar mom
PHP's parser is not "greedy", and once it finds the first []
key for an array variable, it doesn't scan further for more keys. That means the child arrays keys will be ignored, and now you're printing an array in string context, which is simply the literal word Array
.
Ditto for objects:
$foo = new StdClass;
$foo->bar = new StdClass;
$foo->bar->baz = 'qux';
echo "hi $foo->bar->baz mom"; // prints: PHP catchable: Object of StdClass could not be converted to string
echo "hi {$foo->bar->baz} mom"; // prints: hi qux mom
In both cases, the non-braced versions will be parsed/executed as the equivalent of:
echo "hi " . $foo[1] . "[2] mom";
echo "hi " . $foo->bar . "->baz mom";