3v4l.org

run code in 300+ PHP versions simultaneously
<?php $times = ['17:45', '13:12', '09:29', '17:32', '16:49', '14:18']; $counts = array_reduce($times, function($counts, $time) { $hour = (int)substr($time, 0, 2); $moment = in_array($hour, range(9, 12)) ? 'morning' : (in_array($hour, range(13, 16)) ? 'afternoon' : 'evening'); $counts[$moment]++; return $counts; }, ['morning' => 0, 'afternoon' => 0, 'evening' => 0]); echo '<pre>'; var_dump($counts); echo '</pre>';

preferences:
26.26 ms | 408 KiB | 5 Q