PHP $string{0} vs. $string;

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 []?



use $string[0], the other method (braces) is being deprecated in PHP6 (src)

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.

Need Your Help

Null Pointer Exception When Retrieving Custom Parcelables

android arraylist nullpointerexception custom-attributes parcelable

So I have been looking through StackOverFlow and can't seem to find a topic that completely resolves my problem. Many people have had problems with Null Pointer Exceptions while trying to use custom

In MySql, find strings with a given prefix

sql mysql

In MySql, I want to locate records where the string value in one of the columns begins with (or is the same as) a query string. The column is indexed with the appropriate collation order. There is no