3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $dates = [ '03-08-15 12:07:16 PM', '03-08-15 01:54:16 PM', '03-08-15 01:53:16 PM', '03-08-15 02:18:35 PM', '03-08-15 06:32:17 PM', '04-08-15 11:40:25 AM', '04-08-15 01:47:23 PM', '04-08-15 02:13:31 PM', '04-08-15 05:46:10 PM', '05-08-15 11:36:20 AM', '05-08-15 01:43:04 PM', '05-08-15 02:25:14 PM', '05-08-15 06:06:24 PM', '06-08-15 11:25:31 AM', '06-08-15 01:52:32 PM', ]; $newDates = []; foreach ($dates as $date) { $dataTime = DateTime::createFromFormat('d-m-y H:i:s A', $date); $newDates[$dataTime->format('d-m-y')][$dataTime->format('h')] = $dataTime->format('h:i:s A'); } var_dump($newDates);
based on 8X8Wg
Output for 5.6.38 - 7.3.0rc3
array(4) { ["03-08-15"]=> array(4) { [12]=> string(11) "12:07:16 PM" ["01"]=> string(11) "01:53:16 PM" ["02"]=> string(11) "02:18:35 PM" ["06"]=> string(11) "06:32:17 PM" } ["04-08-15"]=> array(4) { [11]=> string(11) "11:40:25 AM" ["01"]=> string(11) "01:47:23 PM" ["02"]=> string(11) "02:13:31 PM" ["05"]=> string(11) "05:46:10 PM" } ["05-08-15"]=> array(4) { [11]=> string(11) "11:36:20 AM" ["01"]=> string(11) "01:43:04 PM" ["02"]=> string(11) "02:25:14 PM" ["06"]=> string(11) "06:06:24 PM" } ["06-08-15"]=> array(2) { [11]=> string(11) "11:25:31 AM" ["01"]=> string(11) "01:52:32 PM" } }