[PHP]: What does array_search() return if nothing was found?
if you're just checking if the value exists, in_array is the way to go.
Quoting the manual page of array_search()
:
Returns the key for needle if it is found in the array,
FALSE
otherwise.
Which means you have to use something like :
$found = array_search($needle, $haystack);
if ($found !== false) {
// do stuff
// when found
} else {
// do different stuff
// when not found
}
Note I used the !==
operator, that does a type-sensitive comparison ; see Comparison Operators, Type Juggling, and Converting to boolean for more details about that ;-)