Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can boolean needle be passed to in_array?

Tags:

php

boolean

Can I pass false as a needle to in_array()?

if(in_array(false,$haystack_array)){
    return '!';
}else{
    return 'C';
}

The $haystack_array will contain only boolean values. The haystack represents the results of multiple write queries. I'm trying to find out if any of them returned false, and therefore not completed.

like image 225
kevtrout Avatar asked Jan 19 '23 03:01

kevtrout


1 Answers

PHP won't care what you pass in as your 'needle', but you should probably also use the third (optional) parameter for in_array to make it a 'strict' comparison. 'false' in PHP will test as equal to 0, '', "", null, etc...

like image 55
Marc B Avatar answered Jan 22 '23 15:01

Marc B