PHP curly braces in array notation

It is mentioned in the manual. {} is just an alternative syntax to [] § Accessing array elements with square bracket syntax. This method is deprecated as of PHP 7.4.0 and no longer supported as of PHP 8.0.0.

Note:

Prior to PHP 8.0.0, square brackets and curly braces could be used interchangeably for accessing array elements (e.g. $array[42] and $array{42} would both do the same thing in the example above). The curly brace syntax was deprecated as of PHP 7.4.0 and no longer supported as of PHP 8.0.0.

The same goes the strings § String access and modification by character :

Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string using square array brackets, as in $str[42]. Think of a string as an array of characters for this purpose. […]

Note: Prior to PHP 8.0.0, strings could also be accessed using braces, as in $str{42}, for the same purpose. This curly brace syntax was deprecated as of PHP 7.4.0 and no longer supported as of PHP 8.0.0.

Leave a Comment