Monkuar Posted March 1, 2012 Share Posted March 1, 2012 $colorarray = isset($_POST['form']['color']) ? intval($_POST['form']['color']) : 0; $color = array( "1", "2", "3", "4", "5", "6", "7", "8", "8", "9", "10", "11", "12", "13", "14", "15", "16" ); if (in_array($color, $colorarray)) { echo "search found"; exit; }else{ echo "hacker"; exit; } i submit my $_POST['form']['color'] as 1 through 16 and it always says hacker? Link to comment https://forums.phpfreaks.com/topic/258034-in_array-broke/ Share on other sites More sharing options...
dragon_sa Posted March 1, 2012 Share Posted March 1, 2012 try this maybe $colorarray = (isset($_POST['form']['color']) ? intval($_POST['form']['color']) : 0); from what I have read you need the brackets to get the expected values, tbh I am not certain if that is the only issue here Link to comment https://forums.phpfreaks.com/topic/258034-in_array-broke/#findComment-1322682 Share on other sites More sharing options...
creata.physics Posted March 1, 2012 Share Posted March 1, 2012 Please use print_r($colorarray) so we can see what is returned. Link to comment https://forums.phpfreaks.com/topic/258034-in_array-broke/#findComment-1322687 Share on other sites More sharing options...
GingerRobot Posted March 1, 2012 Share Posted March 1, 2012 1.) You seem to have the arguments to in_array() the wrong way around: http://php.net/manual/en/function.in-array.php 2.) Unless this is a simplification, why use in_array() anyway? Surely this would suffice: if($i >= 1 && $i <= 16){ //valid }else{ //invalid } Link to comment https://forums.phpfreaks.com/topic/258034-in_array-broke/#findComment-1322692 Share on other sites More sharing options...
requinix Posted March 1, 2012 Share Posted March 1, 2012 1.) You seem to have the arguments to in_array() the wrong way around: http://php.net/manual/en/function.in-array.php Either that or they're the right way around and the variable names are backwards... Link to comment https://forums.phpfreaks.com/topic/258034-in_array-broke/#findComment-1322698 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.