note 39594 added to language.types.array
| From: | elricatchrissid dot o dot tde at rn2 dot php dot net | Date: | Tue, 03 Feb 2004 17:54:32 +0000 |
| Subject: | note 39594 added to language.types.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64608@lists.php.net to get a copy of this message | ||
Hi Steffen,
The reason why 'test' is treated as 0 is that in
$x = "String";
$x [ <something> ]
is NOT an Array subscript, but an (old) way to extract an character from $x ...
Strings are NOT really treated as Arrays, but since it seemed natural to do something like $str [4]
(at least for us C-programmers) ...
What happens is: 'test' is casted (silently, of course) to an integer; thus yielding 0. If
you tried $x ['3 dogs'] you should get the character at index 3.
According to http://www.php.net/manual/en/language.types.string.php
the correct syntax for accessing a character inside a string is now: $x{idx} (which can't be
confused with Array-subscripting anymore).
----
Manual Page -- http://www.php.net/manual/en/language.types.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39594
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39594&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39594&report=yes
Search -- http://master.php.net/manage/user-notes.php