Richard Lynch wrote: > On Fri, December 1, 2006 9:28 am, Ray Hauge wrote: >> I forgot to mention that you won't be able to use "0", "1", etc. as >> PHP >> will convert those to integers. If you do use them, then they will >> replace [0] with whatever you put in there, and if you are using the >> references, it will replace both instances with your new ["0"] > > You can type-cast to (string) to force a string key. > > $foo[(string) '1'] = 'foo'; > > should, I think, have a string key... > > At least I know for sure that it works for float keys... > > You'll have to try it and see for '1' -- I could be way off base.
in cases whether the key you are 'looking up' is numeric php doesn't care whether you use an integer or string - as far as php is concerned "1" and 1 point to exactly the same array item: php -r '$v = array("foo","bar"); var_dump($v["0"],$v[0], $v["1"], $v[1]);' I find this quite handy - though it does help to actually know about this particular behaviour :-) > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php