ZachMEdwards Posted July 13, 2010 Share Posted July 13, 2010 I've got an array of ints. I need to see if an index (for example 15) is in the array, and then read the value. The problem is that in_array is returning false even though it's (clearly) in the array. $t = array(13 => 2, 15 => 9); $x = intval('15'); die(in_array($x, $t) ? 'true' : 'false'); It says false every time. Quote Link to comment https://forums.phpfreaks.com/topic/207572-in_array-with-ints/ Share on other sites More sharing options...
ZachMEdwards Posted July 13, 2010 Author Share Posted July 13, 2010 Found the problem. in_array looks for a value and I'm looking for an index. It's late Thanks #PHP Quote Link to comment https://forums.phpfreaks.com/topic/207572-in_array-with-ints/#findComment-1085206 Share on other sites More sharing options...
bh Posted July 13, 2010 Share Posted July 13, 2010 Hi, you need http://php.net/manual/en/function.array-key-exists.php function Quote Link to comment https://forums.phpfreaks.com/topic/207572-in_array-with-ints/#findComment-1085207 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.