Separate it to make it clearer, starting with the one that works:
<p>{$this->foo['two']}</p> // outputs correct: "2"
It just works.
Now let's look at another one, you think that it does not work:
<p>$this->foo[one]</p> // outputs: "Array[one]"
What actually happens here:
$this->foo is read as the name of the variable to be converted to a string. Then this is Array . Comparable to:
echo $this->foo;
The rest that follows is simply parsed as a string, so you get
<p>Array[one]</p>
for
<p>$this->foo[one]</p> // outputs: "Array[one]"
This is the same as:
<p>{$this->foo}[one]</p> // outputs: "Array[one]"
The curly braces help PHP to parse correctly. You can more specifically express what part you would like to be a variable expression in a line with curly braces.
hakre source share