How do i check if all keys in an array have empty values in PHP?

Viewed 26049

I have an array

$array = array('key1' => null, 'key2' => null, 'key3' => null, 'key4' => null);

i would like to determine if all the array keys have empty values if so then return false. the above example should return false as it does not have any value. but if one or more keys have any values then it should return true for example the below example is true.

$array = array('key1', 'key2' => value2, 'key3', 'key4' => value4);
7 Answers

Simple

count(array_filter($array)) != count($array)

If multidimensional

count(array_filter(array_values($array))) != count(array_values($array))
Related