angelcool Posted November 5, 2008 Share Posted November 5, 2008 Hello community, Does anyone know where exactly in the php manual is explained the next functionality: $string= 'abcdefg'; echo $string[4]; ...this works and outputs: 'e' this look like some sort of array, but I just can find it explained in the php manual. Any link for an exact explanation will be apreciated. Thank you. Angel Link to comment https://forums.phpfreaks.com/topic/131549-string-abcdefg-echo-string4/ Share on other sites More sharing options...
akitchin Posted November 5, 2008 Share Posted November 5, 2008 when used on a string, the index notation refers to the character in that string. 'e' is the 5th character in the string, which is index 4 (since indexes start at 0). $string[0] would be 'a', etc. Link to comment https://forums.phpfreaks.com/topic/131549-string-abcdefg-echo-string4/#findComment-683220 Share on other sites More sharing options...
Michdd Posted November 5, 2008 Share Posted November 5, 2008 It's simple. It's outputting byte #4 in the string. But php starts counting from 0. Like: a = 0 b = 1 c = 2 d = 3 e = 4 In that example you gave. Link to comment https://forums.phpfreaks.com/topic/131549-string-abcdefg-echo-string4/#findComment-683221 Share on other sites More sharing options...
angelcool Posted November 5, 2008 Author Share Posted November 5, 2008 Thank you for your fast reply. I do understand how this concept works, but would this be in the PHP manual? Link to comment https://forums.phpfreaks.com/topic/131549-string-abcdefg-echo-string4/#findComment-683222 Share on other sites More sharing options...
akitchin Posted November 5, 2008 Share Posted November 5, 2008 it is, in the variables section. is there any particular reason you want to find it in the manual, despite understanding how it works? Link to comment https://forums.phpfreaks.com/topic/131549-string-abcdefg-echo-string4/#findComment-683246 Share on other sites More sharing options...
angelcool Posted November 5, 2008 Author Share Posted November 5, 2008 there is not exactly a particular reason for this issue, I just wanted to find it in the manual that is pretty much it. perhaps self-satisfaction(maybe laziness to find it myself). i'll look in the variables section, thank you. = ) Link to comment https://forums.phpfreaks.com/topic/131549-string-abcdefg-echo-string4/#findComment-683262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.