Jump to content

in_array broke


Monkuar

Recommended Posts

$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?  :confused:

Link to comment
https://forums.phpfreaks.com/topic/258034-in_array-broke/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.