Reputation: 7337
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?
Upvotes: 4
Views: 3232
Reputation: 41810
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.
Upvotes: 10
Reputation: 7337
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.
Upvotes: 2