Reputation: 457
How can I setup the function array_keys to return all keys in my array that have values that are not equal to zero.
Upvotes: 0
Views: 1612
Reputation:
You can do this by filtering the array first:
$results = array('ab' => 0, 'ba' => 53, 'pl' => 23, 'ct' => 0);
$non_zero = array_keys(array_filter($results, function($item)
{
return $item !== 0;
}));
// Value of $non_zero:
// array('ba', 'pl')
Upvotes: 4