Welcome to WebmasterWorld Guest from 54.163.52.98

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

simple in array question

     

tec4

4:41 am on Feb 24, 2012 (gmt 0)



No idea why this is not working for me...perhaps i'm just super tired and my logic is off but is driving me crazy! lol

Have a simple array, like:


$ret_array = Array ( [97381816989] => 1 [97381821414] => 1 [97381821534] => 1 [97381823199] => 1 )


and I try to check to see if the number 78 is in the array (which it should not be), like:


if (!in_array(78,$ret_array)) {
echo "NOT in array";
} else {
echo "IS in array";
}



The result is "Is in array" when I run this..also tried replacing the numeric 78 with a string like "word" and it still echos "IS in array" - am I overlooking something? lol

Thanks for the help!

enigma1

11:13 am on Feb 24, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



use the 3rd parameter for a strict check and see if it works

in_array(78,$ret_array, true)

g1smd

11:28 am on Feb 24, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Your example code seems to be missing punctuation between array elements.

penders

8:19 pm on Mar 2, 2012 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Your example code seems to be missing punctuation between array elements.


The example (pseudo) code looks like the output from print_r()? (There shouldn't be square brackets around the array indices either) - but if this was executed as-is you'd get a fatal parse error, not "Is in array".

Is this being run on a 64-bit system? 97381816989 is outside the 32-bit integer range, so this is not going to be preserved on a 32-bit system. Although I don't think this should affect the immediate in_array() problem?!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month