As a rule, you do not need parentheses around variables, unless you need to force PHP to treat something as a variable, where otherwise its normal parsing rules cannot. Large - multidimensional arrays. The PHP parser is not greedy for deciding what a variable is and what is not, so brackets are needed to make PHP see the rest of the references to the elements of the array:
<?php $arr = array( 'a' => array( 'b' => 'c' ), ); print("$arr[a][b]"); // outputs: Array[b] print("{$arr[a][b]}"); // outputs: (nothing), there no constants 'a' or 'b' defined print("{$arr['a']['b']}"); // ouputs: c
source share