Another solution:
$array = array('one', 'two', '');
if(count(array_filter($array)) == count($array)) {
echo 'OK';
} else {
echo 'ERROR';
}
Also,
$containsEmpty = in_array("", $arr);
Should be a bit faster as it doesn’t have to trace the entire array and doesn’t have to create a new array.
Note that both solutions will consider 0
, false
, null
and empty array as empty values as well.
In case you also consider a value empty if it consists of space-like characters only, see the answer below