phparraysconditional-statementsbooleanboolean-logic

Check if a flat array is comprised wholly of true or wholly of false values


How can I check if all elements in an array are true, or if all elements are false?

Ideally, I am trying to avoid a really long if expression.

array('a'=> true, 'b'=> true, ...)

To clarify the expected result:


Solution

  • if(count(array_unique($your_array)) === 1)  
      return current($your_array);
    
    else return;