3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = array( "2014-01-20 20:00:00", "2014-01-21 20:00:00", "2014-01-22 14:00:00", "2014-01-22 20:00:00", "2014-01-23 14:00:00", "2014-01-23 20:00:00", "2014-01-25 20:00:00", "2014-01-26 12:00:00", "2014-01-26 20:00:00", "2014-01-31 20:00:00", "2014-02-01 20:00:00" ); $timestamps = array_map("strtotime", $input); $calendar = array(); foreach ($timestamps as $value) { $format = date("d.m.H", $value); list($day, $month, $hour) = explode(".", $format); if (!array_key_exists($month, $calendar)) $calendar[ $month ] = array(); if (!array_key_exists($day, $calendar[ $month ])) $calendar[ $month ][ $day ] = array(); $calendar[ $month ][ $day ][] = $hour; } $ranges = array(); // use reference so removing objects will affect all loops foreach ($calendar as $month => &$dates) { foreach ($dates as $date => $hours) { foreach ($hours as $key=>$hour) { // start checking for groups $currentDate = $date+1; $range = array($date); while (isset($dates[$currentDate]) && ($newkey = array_search($hour, $dates[$currentDate])) !== FALSE) { $range[] = $currentDate; unset($dates[$currentDate][$newkey]); $currentDate++; } // group was found if (count($range) != 1) { $ranges[] = array('dates' => $range, 'hour' => $hour); unset($dates[$date][$key]); } } } } print_r($calendar); print_r($ranges);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [01] => Array ( [20] => Array ( ) [21] => Array ( ) [22] => Array ( ) [23] => Array ( ) [25] => Array ( ) [26] => Array ( [0] => 12 ) [31] => Array ( [0] => 20 ) ) [02] => Array ( [01] => Array ( [0] => 20 ) ) ) Array ( [0] => Array ( [dates] => Array ( [0] => 20 [1] => 21 [2] => 22 [3] => 23 ) [hour] => 20 ) [1] => Array ( [dates] => Array ( [0] => 22 [1] => 23 ) [hour] => 14 ) [2] => Array ( [dates] => Array ( [0] => 25 [1] => 26 ) [hour] => 20 ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.92 ms | 404 KiB | 8 Q