What is the difference between $str[n] and $str{n}, given that $str is a string.
I noticed that both seem to work the same, except that {} does not occur in any documentation I found.
What is the difference between $str[n] and $str{n}, given that $str is a string.
I noticed that both seem to work the same, except that {} does not occur in any documentation I found.
They are the same. However, they are getting rid of the {}
syntax, so you should go with []
.
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: Strings may also be accessed using braces, as in $str{42}, for the same purpose. However, this syntax is deprecated as of PHP 6. Use square brackets instead.