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);
To check if all of the values in an array are equal to null , use the every() method to iterate over the array and compare each value to null , e.g. arr. every(value => value === null) . The every method will return true if all values in the array are equal to null .
The array_keys() function returns an array containing the keys.
The in_array() function is an inbuilt function in PHP that is used to check whether a given value exists in an array or not. It returns TRUE if the given value is found in the given array, and FALSE otherwise.
Assuming you actually mean an array like
array('key1' => null, 'key2' => null, 'key3' => null, 'key4' => null)
the answer is simply
if (!array_filter($array)) {
// all values are empty (where "empty" means == false)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With