homepage Welcome to WebmasterWorld Guest from 54.161.191.154
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
simple in array question
tec4



 
Msg#: 4421212 posted 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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4421212 posted 11:13 am on Feb 24, 2012 (gmt 0)

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

in_array(78,$ret_array, true)

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4421212 posted 11:28 am on Feb 24, 2012 (gmt 0)

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

penders

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



 
Msg#: 4421212 posted 8:19 pm on Mar 2, 2012 (gmt 0)

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?!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved