In PHP you can access characters of strings in a few different ways, one of which is substr(). You can also access the Nth character in a string with curly or square braces, like so:
$string = 'hello'; echo $string{0}; // h echo $string[0]; // h
My question is, is there a benefit of one over the other? What’s the difference between {} and []?
Thanks.
use
$string[0], the other method (braces) has been removed in PHP 8.0.For strings:
And for arrays: