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); echo
Output for 5.4.0 - 5.4.25
Parse error: syntax error, unexpected end of file in /in/qQOZu on line 50
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected '[' in /in/qQOZu on line 3
Process exited with code 255.

preferences:
190.36 ms | 1395 KiB | 62 Q