I need to check if all values in an array equal the same thing.
For example:
$allValues = array(
\'true\',
\'true\',
\'true\',
);
If your array contains actual booleans (or ints) instead of strings, you could use array_sum:
$allvalues = array(TRUE, TRUE, TRUE);
if(array_sum($allvalues) == count($allvalues)) {
echo 'all true';
} else {
echo 'some false';
}
http://codepad.org/FIgomd9X
This works because TRUE
will be evaluated as 1
, and FALSE
as 0
.