Thread: in_array oddity
View Single Post

  #4 (permalink)  
Old 10-12-2004
Tom Barnes
 
Posts: n/a
Default Re: in_array oddity

nospam1978@yahoo.com (Tom Barnes) wrote in message news:<5af28966.0410111503.f6f243f@posting.google.c om>...
> Check out this code:
>
> // Start Code -------------
> function test_in_array($val)
> {
> $a = array('key' => $val);
> printf("in_array: %d, value:%s<BR>", in_array('key', $a), $a['key']);
> }
> test_in_array(0);
> test_in_array(1);
> // End Code ---------------
>
> The output I get is:
>
> in_array: 1, value:0
> in_array: 0, value:1
>
> Why does the second in_array() call fail???


I'm so stupid, for some reason I thought in_array() was searching for
keys. I should use array_key_exists() instead. Thanks Brion and Pedro.
Reply With Quote