3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ [ 'time' => '00:00:00', 'sales' => 55.99, 'orders' => 1, ], [ 'time' => '06:00:00', 'sales' => 46.37, 'orders' => 1, ], [ 'time' => '08:00:00', 'sales' => 246.56, 'orders' => 4, ], [ 'time' => '10:00:00', 'sales' => 78.66, 'orders' => 1, ] ]; // isolate the times $times = array_map(function ($row) { return $row['time']; }, $rows); // create a list of similarly formatted times from 00:00:00 - 22:00:00 $allTimes = array_map(function ($hour) { return sprintf('%02d:00:00', $hour); }, range(0, 22, 2)); // compute the difference $notTimes = array_diff($allTimes, $times); // add the notTimes to the original rowset with default values foreach ($notTimes as $notTime) { $rows[] = [ 'time' => $notTime, 'sales' => 0, 'orders' => 0, ]; } var_dump($rows);
Output for git.master, git.master_jit, rfc.property-hooks
array(12) { [0]=> array(3) { ["time"]=> string(8) "00:00:00" ["sales"]=> float(55.99) ["orders"]=> int(1) } [1]=> array(3) { ["time"]=> string(8) "06:00:00" ["sales"]=> float(46.37) ["orders"]=> int(1) } [2]=> array(3) { ["time"]=> string(8) "08:00:00" ["sales"]=> float(246.56) ["orders"]=> int(4) } [3]=> array(3) { ["time"]=> string(8) "10:00:00" ["sales"]=> float(78.66) ["orders"]=> int(1) } [4]=> array(3) { ["time"]=> string(8) "02:00:00" ["sales"]=> int(0) ["orders"]=> int(0) } [5]=> array(3) { ["time"]=> string(8) "04:00:00" ["sales"]=> int(0) ["orders"]=> int(0) } [6]=> array(3) { ["time"]=> string(8) "12:00:00" ["sales"]=> int(0) ["orders"]=> int(0) } [7]=> array(3) { ["time"]=> string(8) "14:00:00" ["sales"]=> int(0) ["orders"]=> int(0) } [8]=> array(3) { ["time"]=> string(8) "16:00:00" ["sales"]=> int(0) ["orders"]=> int(0) } [9]=> array(3) { ["time"]=> string(8) "18:00:00" ["sales"]=> int(0) ["orders"]=> int(0) } [10]=> array(3) { ["time"]=> string(8) "20:00:00" ["sales"]=> int(0) ["orders"]=> int(0) } [11]=> array(3) { ["time"]=> string(8) "22:00:00" ["sales"]=> int(0) ["orders"]=> int(0) } }

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:
42.99 ms | 404 KiB | 8 Q