Dev.Wol Dev.Wol - 1 year ago 67
PHP Question

Count Number of Items In array above 0

I have an array

array:3 [▼
1 => "2"
2 => "2"
3 => "0"

I want to count the number of keys which have the value over 0. In the above example I should have the answer 2.

Here's my attempt.

return count($input_items > 0);

This returns 1

Answer Source

You can use array_filter as:


If you don’t supply a callback function, it filters all values out that equal false (boolean conversion).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download