3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); $data = [ '2020-07-14' => [ [ 'start_time' => '14:15:00', 'end_time' => '17:45:00', ],[ 'start_time' => '14:30:00', 'end_time' => '17:30:00', ],[ 'start_time' => '14:30:00', 'end_time' => '17:30:00', ], ], ]; function getSortedDays(array $days): array { return array_map(function (array $day) { array_multisort(array_column($day, 'start_time'), SORT_ASC, $day); return $day; }, $days); } function addTotalAttendedHours(array $days): array { $sortedDays = getSortedDays($days); $days = array_map(function (array $day) { $sum = (new DateTime())->setTimestamp(0); $previousEnd = null; foreach ($day as $time) { $currentStart = new DateTimeImmutable($time['start_time']); $currentEnd = new DateTimeImmutable($time['end_time']); if ($currentEnd < $previousEnd) continue; $sum->add($currentStart->diff($currentEnd)); if ($previousEnd !== null && $currentStart < $previousEnd) { $sum->sub($currentStart->diff($previousEnd)); } $previousEnd = $currentEnd; } $attendedSeconds = $sum->getTimestamp(); $day['total_attended_hours'] = sprintf( '%02u:%02u:%02u', $attendedSeconds / 60 / 60, ($attendedSeconds / 60) % 60, $attendedSeconds % 60 ); return $day; }, $sortedDays); return $days; } var_dump(addTotalAttendedHours($data));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.20.0090.00625.93
8.4.10.0030.01621.24
8.3.150.0150.00316.80
8.3.140.0050.00317.16
8.3.130.0060.00317.23
8.3.120.0030.00620.73
8.3.110.0080.00816.78
8.3.100.0030.00618.68
8.3.90.0090.00026.77
8.3.80.0090.00017.00
8.3.70.0060.00916.88
8.3.60.0130.01016.88
8.3.50.0070.00924.63
8.3.40.0090.00618.95
8.3.30.0070.00718.97
8.3.20.0000.00824.18
8.3.10.0040.00424.66
8.3.00.0080.00026.16
8.2.270.0160.00316.74
8.2.260.0120.00617.07
8.2.250.0100.00016.96
8.2.240.0070.01017.23
8.2.230.0040.00420.94
8.2.220.0090.00024.06
8.2.210.0070.00726.77
8.2.200.0090.00017.00
8.2.190.0160.00617.13
8.2.180.0140.00025.92
8.2.170.0090.00619.04
8.2.160.0110.00422.96
8.2.150.0040.00425.66
8.2.140.0000.00724.66
8.2.130.0040.00426.16
8.2.120.0080.00026.35
8.2.110.0090.00021.04
8.2.100.0090.00317.83
8.2.90.0000.00817.73
8.2.80.0030.00720.07
8.2.70.0080.00017.75
8.2.60.0080.00017.88
8.2.50.0040.00418.05
8.2.40.0090.00018.28
8.2.30.0000.00818.15
8.2.20.0000.00718.14
8.2.10.0030.00519.32
8.2.00.0070.00019.39
8.1.310.0000.01416.78
8.1.300.0150.00320.32
8.1.290.0110.00030.84
8.1.280.0070.01125.92
8.1.270.0080.00023.99
8.1.260.0000.00728.09
8.1.250.0040.00428.09
8.1.240.0000.01023.66
8.1.230.0100.00322.66
8.1.220.0060.00317.91
8.1.210.0090.00018.90
8.1.200.0060.00317.60
8.1.190.0000.00917.47
8.1.180.0040.00418.10
8.1.170.0040.00418.63
8.1.160.0000.00819.04
8.1.150.0030.00619.09
8.1.140.0040.00419.05
8.1.130.0070.00020.23
8.1.120.0040.00417.73
8.1.110.0040.00417.68
8.1.100.0000.00817.68
8.1.90.0050.00317.61
8.1.80.0050.00317.62
8.1.70.0000.00817.58
8.1.60.0030.00617.63
8.1.50.0040.00417.68
8.1.40.0080.00017.55
8.1.30.0030.00517.81
8.1.20.0040.00417.78
8.1.10.0030.00617.71
8.1.00.0040.00417.68
8.0.300.0000.00719.98
8.0.290.0040.00417.00
8.0.280.0000.00720.12
8.0.270.0040.00418.21
8.0.260.0030.00320.14
8.0.250.0000.00717.20
8.0.240.0030.00317.35
8.0.230.0000.00717.29
8.0.220.0000.00717.18
8.0.210.0040.00417.08
8.0.200.0030.00317.07
8.0.190.0040.00417.20
8.0.180.0000.00717.09
8.0.170.0050.00317.05
8.0.160.0050.00317.09
8.0.150.0040.00417.06
8.0.140.0040.00417.11
8.0.130.0000.00613.47
8.0.120.0070.00017.10
8.0.110.0040.00417.00
8.0.100.0040.00417.13
8.0.90.0030.00517.00
8.0.80.0090.00717.01
8.0.70.0000.00817.07
8.0.60.0020.00517.07
8.0.50.0000.00717.07
8.0.30.0060.01017.35
8.0.20.0120.00717.30
8.0.10.0000.00817.05
8.0.00.0110.00816.95
7.4.330.0050.00015.55
7.4.320.0060.00016.80
7.4.300.0000.00616.80
7.4.290.0070.00016.76
7.4.280.0040.00416.66
7.4.270.0030.00516.76
7.4.260.0050.00013.42
7.4.250.0070.00016.74
7.4.240.0030.00316.78
7.4.230.0070.00016.84
7.4.220.0020.00516.72
7.4.210.0070.00816.72
7.4.200.0030.00316.66
7.4.130.0090.01216.61
7.4.120.0120.01316.62
7.4.110.0170.00316.77
7.4.100.0170.00716.80
7.4.90.0130.01016.80
7.4.80.0130.01016.46
7.4.70.0110.00816.71
7.4.60.0120.00816.65
7.4.50.0060.01916.47
7.4.40.0190.00616.48
7.4.30.0120.01516.79
7.4.20.0170.01216.71
7.4.10.0130.01316.70
7.4.00.0100.01316.69
7.3.330.0030.00316.36
7.3.320.0060.00013.45
7.3.310.0030.00316.46
7.3.300.0030.00316.39
7.3.290.0060.01016.50
7.3.280.0140.00016.44
7.3.260.0060.01316.76
7.3.230.0030.01416.90
7.3.210.0000.01616.46
7.3.200.0120.01016.74
7.3.190.0080.01216.55
7.3.180.0140.00716.55
7.3.170.0190.00616.71
7.3.160.0110.01116.77
7.3.150.0150.00716.53
7.3.140.0100.01616.52
7.3.130.0150.00916.51
7.3.120.0120.01216.53
7.3.110.0140.01116.44
7.3.100.0160.01016.41
7.3.90.0140.00516.68
7.3.80.0090.01516.50
7.3.70.0190.00616.64
7.3.60.0110.00616.61
7.3.50.0120.00916.63
7.3.40.0160.00316.54
7.3.30.0140.00316.74
7.3.20.0120.00916.47
7.3.10.0090.01216.55
7.3.00.0180.00916.65
7.2.330.0140.00416.97
7.2.320.0170.00316.96
7.2.310.0130.00517.00
7.2.300.0190.00716.61
7.2.290.0150.00916.72
7.2.280.0130.01316.74
7.2.270.0120.01217.10
7.2.260.0110.01116.68
7.2.250.0200.00316.98
7.2.240.0140.01116.89
7.2.230.0060.01816.81
7.2.220.0150.00816.94
7.2.210.0140.00716.64
7.2.200.0130.01016.80
7.2.190.0130.01016.83
7.2.180.0190.00316.84
7.2.170.0070.01416.95
7.2.160.0060.01216.75
7.2.150.0160.00516.74
7.2.140.0130.01316.80
7.2.130.0140.01116.97
7.2.120.0090.01016.79
7.2.110.0110.00816.88
7.2.100.0180.00716.86
7.2.90.0130.01316.86
7.2.80.0070.01416.86
7.2.70.0130.01316.78
7.2.60.0130.00716.83
7.2.50.0160.01016.83
7.2.40.0100.01016.95
7.2.30.0130.01316.80
7.2.20.0160.00716.80
7.2.10.0080.01716.96
7.2.00.0030.01617.02

preferences:
28.95 ms | 403 KiB | 5 Q