Ok, I will collect my comments as an answer:
Quote manual
You can also use curly braces to access strings, as in $ str {42}, for the same purpose. However, this syntax has been deprecated since PHP 7. Use square brackets instead.
Also, although undocumented, the {} accessor also works for arrays, which makes $ foo {$ bar} and $ foo [$ bar] completely equivalent. This is just the old syntax for the convenience of Perl programmers.
As for your second question, if it is good practice to treat strings as an array of characters: Yes, if that is useful for your task, do it. In low-level languages ββsuch as C, strings are arrays of characters, so it's natural to treat them like this.
BUT keep in mind that PHP has poor Unicode support. Therefore, if your string is in multibyte encoding (i.e. UTF-8), this may not work as expected. In this case, it is better to use multibyte functions .
Fabian schmengler
source share