3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ '2020-02-07' => ['09:00' => 1500, '10:30' => 1500, '11:00' => 1500], '2020-02-08' => ['09:00' => 1500, '09:30' => 1500, '10:00' => 1500], '2020-02-09' => ['09:00' => 1500, '09:30' => 1500, '11:00' => 1500], '2020-02-10' => ['09:00' => 1500, '10:30' => 1500, '11:30' => 1500] ]; $result = array(); foreach ($array as $date => $arr) { $next_included = false; $times = array_keys($arr); $count = count($times); for ($i = 0; $i < $count - 1; $i++) { $current = $times[$i]; $next = $times[$i+1]; if (strtotime($next) - strtotime($current) == 1800) { $result[$date][] = "$current - $next"; $next_included = true; } else { if (!$next_included) $result[$date][] = $current; $next_included = false; } } if (!$next_included) { $result[$date][] = $next; } } print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [2020-02-07] => Array ( [0] => 09:00 [1] => 10:30 - 11:00 ) [2020-02-08] => Array ( [0] => 09:00 - 09:30 [1] => 09:30 - 10:00 ) [2020-02-09] => Array ( [0] => 09:00 - 09:30 [1] => 11:00 ) [2020-02-10] => Array ( [0] => 09:00 [1] => 10:30 [2] => 11:30 ) )

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:
114.31 ms | 406 KiB | 5 Q