I have an array. How can I get a list of the keys that have null values? Is there some short way to find them?
Actually, array_keys
has an optional search_value parameter, so you can just put:
array_keys($array, null, true);
You must set the third parameter (strict comparison) to true for it to match only nulls.
Here's the function that I came up with:
function find_nulls($a) {
return array_keys(array_filter($a, function($b) {
return is_null($b);
}) );
}
It seems to work as desired.
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