What does array_search() return if nothing was found?
I have the need for the following logic:
$found = array_search($needle, $haystack);
if($found){
//do stuff
} else {
//do different stuff
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Quoting the manual page of
array_search():Which means you have to use something like :
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 😉