note 39594 deleted from language.types.array by curt

From: Date: Tue, 06 Jul 2004 02:22:17 +0000
Subject: note 39594 deleted from language.types.array by curt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72647@lists.php.net to get a copy of this message
Note Submitter: elric at chrissi d.o.t de ---- 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).

« previous php.notes (#72647) next »