3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( '2013-07-19' => 1, '2013-07-21' => 3, '2013-07-23' => 2, '2013-07-24' => 4, '2013-07-25' => 4, '2013-07-26' => 2, '2013-07-27' => 2, '2013-07-30' => 3, '2013-07-31' => 1 ); $result = array(); $ref = new DateTime('1821-11-11'); // or starting with PHP 7.3: $ref = new DateTime(array_key_first($data)); foreach ($data as $datum => $nb) { //if ($ref->add($oneDay)->format('Y-m-d') !== $datum) { if ($ref->modify('+1 day')->format('Y-m-d') !== $datum) { $result[] = array(); $ref->setDate(...explode('-', $datum));// = new DateTime($datum); } $result[count($result) - 1][$datum] = $nb; } print_r($result);
Output for git.master_jit, git.master
Array ( [0] => Array ( [2013-07-19] => 1 ) [1] => Array ( [2013-07-21] => 3 ) [2] => Array ( [2013-07-23] => 2 [2013-07-24] => 4 [2013-07-25] => 4 [2013-07-26] => 2 [2013-07-27] => 2 ) [3] => Array ( [2013-07-30] => 3 [2013-07-31] => 1 ) )

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