I found some odd behavior when I used the in_array() PHP function. I have an array like this:
$arr = [TRUE, "some string", "something else"];
Now, if I want to check if there is a "test" in the array, obviously not, but in_array() still returns TRUE, why?
$result = in_array("test", $arr); var_dump($result); // Output: bool(true)
The same thing happens when using array_search() :
$result = array_search("test", $arr); var_dump($result); // Output: int(0)
I thought it was possible that the TRUE value in the array automatically caused the function to return TRUE for each result without checking the rest of the array, but I could not find any documentation that could offer this very unusual functionality.
source share