Forum Moderators: coopster
I hate when a language is doing something behind my back! Grrrr...
I've got news for you, whether it is Perl, PHP, or any other language you have to know the idiosyncrasies of the language. And in this case, it is no secret behind your back as the developers have been quite open about it ;)
A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08"). Floats in key are truncated to integer.
Resource: [php.net...]
On a side note, the best part is the idiosyncracies between the language and the OS -- that's when the real fun begins!
Ah, the joys of programming! Oh well, hang in there fellas!
A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08"). Floats in key are truncated to integer.
And you also have:
$key = "123" ;
$myArray = array($key => "aValue") ;
$isset = isset($myArray[123]) ; // true
$isset = isset($myArray["123"]) ; // true
It's not really fun to code with pitfalls like this around you! I guess everyone should RTFM 2-3 before starting any project...
I would LOVE to see real hashtables and real arrays in PHP one day.