PHP String Comparison: 0 vs String



The syntax ‘string0hasbeendeprecatedbeginningfromPHPversion6.Hence,itisstronglysuggestedtousestring[0].

In short, accessing characters using the flower braces {} has been deprecated. Hence the square brackets should be used [] −

Example

 Live Demo

$string = 'medium';
echo $string{0};
echo $string[0];

Output

This will produce the following output −

mm
Updated on: 2020-04-07T12:56:04+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements