The shortest way to evaluate an array with booleans (PHP)?

I have an array with booleans in it, what is the shortest way to loop it and get the final boolean expression?

Example : an array with 3 elements (true, false, true) → the result should be false (true && false && true = false)

I know I can go through it, but is there a shorter way?

Thank!

+5
source share
3 answers
if (!in_array(false, $array)) { ...
+17
source

I don't know, but you can

look for false in the array first

if the search is found then the result will be false yet the result is correct.

Not: This is simple and algorithm. not code

+1
source
if (array_sum($array) == count($array)) {
  // All are TRUE; 
}
else {
 // One of them is FALSE;
}
0
source

All Articles