fork(6) download
  1. <?php
  2.  
  3. $times = ['12:05', '14:05', '16:05', '18:05', '20:05'];
  4. $now = new \DateTime();
  5. $filteredTimes = array_filter($times, function ($time) use ($now) {
  6. $diff = (new \DateTime($time))->diff($now);
  7. return $diff->invert && $diff->h * 60 + $diff->i >= 30;
  8. });
  9. echo sprintf("Now: %s\n", $now->format('H:i'));
  10. var_dump($filteredTimes);
  11.  
  12. $filteredTimes = array_filter($times, function ($time) use ($now) {
  13. $diff = (new \DateTime($time))->diff($now);
  14. var_dump((int)$diff->format('%R%i%'));
  15. return (int)$diff->format('%R%i%') > 30;
  16. });
  17. var_dump($filteredTimes);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Now: 15:32
array(3) {
  [2]=>
  string(5) "16:05"
  [3]=>
  string(5) "18:05"
  [4]=>
  string(5) "20:05"
}
int(27)
int(27)
int(-32)
int(-32)
int(-32)
array(0) {
}