remove zero occurrence in array

I am implementing a function to calculate date. the function makes the calculations to find each element: year, month, week, day, hour, minute, second.

the result of the calculation is an array like this:

array (
     [year] => 0
     [month] => 0
     [week] => 0
     [day] => 0
     [hour] => 3
     [minute] => 193
     [second] => 11583

must now remove any occurrence that is KEY = 0, and leave only the indices hour, minute, second.

there's some native PHP function that can do this?

Thank you all


array_filter ( array $input);

Should work. It will delete all elements with value equals to false. If you would like all elements that are === 0 create your own callback function for array_filter like in the link below.

Need Your Help