Jump to content

Display 1st Character


Dysan

Recommended Posts

"[]" is deprecated in favour of "{}" when pulling a character from a string.

 

$first = $str{0};

 

You got it the other way around Barand... From strings:

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 like $str[42] so think of a string as an array of characters.

 

    Note: They may also be accessed using braces like $str{42} for the same purpose. However, using square array-brackets is preferred because the {braces} style is deprecated as of PHP 6.

 

 

Orio.

Link to comment
https://forums.phpfreaks.com/topic/83272-display-1st-character/#findComment-423638
Share on other sites

I know, I just checked the online manual.

 

In my .chm version of the manual which I download

 

Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string in curly braces.

 

????: For backwards compatibility, you can still use array-brackets for the same purpose. However, this syntax is deprecated as of PHP 4.

 

Wish they'd make up their mind !

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/83272-display-1st-character/#findComment-423642
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.