1

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

Papa Charlie
  • 625
  • 8
  • 31
  • possible duplicate of [Remove zero values from a PHP array](http://stackoverflow.com/questions/2287404/remove-zero-values-from-a-php-array) – safarov Apr 08 '12 at 07:29
  • Instead of removing zero keys make date function not to return 0 value – safarov Apr 08 '12 at 07:31

1 Answers1

1
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. http://php.net/manual/en/function.array-filter.php

The GiG
  • 2,571
  • 2
  • 28
  • 29