3v4l.org

run code in 300+ PHP versions simultaneously
<?php $staff = array(1,2,3,4,5); $start = array("11:05", "11:00", "19:00", "13:00", "19:00"); $end = array("16:00", "17:00", "03:00", "16:00", "03:05"); // Add staff number to end of time ex 11:00 => 11:00#2 For($i=0; $i<count($start);$i++){ $start[$i] .= "#" . $staff[$i]; $end[$i] .= "#" . $staff[$i]; } $t = array_merge($start,$end); // create one long array with all in and out times sort($t); // Multisport is needed to get all arrays in time order as reference array_multisort($start, $end, $staff); // Find first start time (11:00) and slice array thwre, build string $test = implode(PHP_EOL,array_slice($t, array_search($start[0], $t))); // Find the times before first start (night end times) and add them last in string $test .= PHP_EOL . implode(PHP_EOL,array_slice($t, 0,array_search($start[0], $t))); $times = explode(PHP_EOL, $test); // explode to make it array again // Var_dump($times); $WhoIsInDaHouse = array("dummy"); // add a dummy variable since 0=false in later if $j=0; for($i=0; $i<count($times);$i++){ $TimePerson = explode("#", $times[$i]); $Time = $TimePerson[0]; $person = $TimePerson[1]; $inout = array_search($person, $WhoIsInDaHouse); //is person in house and about to leave? If($inout != false){ //if person enter work false, if true: key of person leaving in $WhoIsInDaHouse //Here $person is leaving work Unset($WhoIsInDaHouse[$inout]); If(count($WhoIsInDaHouse) == 2){ // someone will now be alone since we have a dummy $Alone[$j]["start"] = $Time; $Alone[$j]["who"] = array_slice($WhoIsInDaHouse, -1)[0]; }elseif(count($WhoIsInDaHouse) == 1 && $prevcount == 2){ // Only dummy left $Alone[$j]["end"] = $Time; $Alone[$j]["duration"] = strtotime($Alone[$j]["end"])-strtotime($Alone[$j]["start"]); $j++; } }Else{ // Here person enters work $WhoIsInDaHouse[] = $person; If(count($WhoIsInDaHouse) == 2){ // someone is entering alone $Alone[$j]["start"] = $Time; $Alone[$j]["who"] = $person; }elseif(count($WhoIsInDaHouse)>2 && $prevcount == 2){ // not alone anymore $Alone[$j]["end"] = $Time; $Alone[$j]["duration"] = strtotime($Alone[$j]["end"])-strtotime($Alone[$j]["start"]); $j++; } } $prevcount = count($WhoIsInDaHouse); } Var_dump($Alone);

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.120.0090.00220.67
8.4.110.0110.01022.49
8.4.100.0120.00918.01
8.4.90.0060.00518.92
8.4.80.0090.00319.80
8.4.70.0080.00818.37
8.4.60.0130.00819.08
8.4.50.0080.00318.74
8.4.40.0140.00719.55
8.4.30.0080.01219.79
8.4.20.0130.00717.82
8.4.10.0030.00619.59
8.3.250.0130.00619.08
8.3.240.0100.00917.39
8.3.230.0130.00716.65
8.3.220.0090.01017.23
8.3.210.0080.01116.61
8.3.200.0060.00416.84
8.3.190.0120.01017.01
8.3.180.0060.00316.77
8.3.170.0180.00016.99
8.3.160.0140.00618.61
8.3.150.0170.00317.43
8.3.140.0040.00417.46
8.3.130.0030.00616.80
8.3.120.0050.00519.29
8.3.110.0090.00620.94
8.3.100.0060.00324.06
8.3.90.0070.00326.77
8.3.80.0060.00318.80
8.3.70.0190.00316.63
8.3.60.0160.00316.63
8.3.50.0110.00917.47
8.3.40.0040.01118.98
8.3.30.0070.00719.04
8.3.20.0040.00420.36
8.3.10.0080.00023.48
8.3.00.0080.00019.91
8.2.290.0060.00420.30
8.2.280.0120.00818.63
8.2.270.0060.01018.86
8.2.260.0000.00818.41
8.2.250.0030.00618.45
8.2.240.0110.00017.30
8.2.230.0060.00322.58
8.2.220.0100.00037.54
8.2.210.0050.00326.77
8.2.200.0060.00316.75
8.2.190.0110.00716.74
8.2.180.0040.01816.63
8.2.170.0090.00622.96
8.2.160.0140.00019.16
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0040.00420.94
8.2.110.0090.00022.20
8.2.100.0030.00918.09
8.2.90.0140.00318.93
8.2.80.0040.00418.05
8.2.70.0040.00417.84
8.2.60.0000.00817.93
8.2.50.0040.00418.16
8.2.40.0000.00921.87
8.2.30.0050.00319.42
8.2.20.0050.00318.23
8.2.10.0080.00018.10
8.2.00.0030.00618.09
8.1.330.0100.00821.99
8.1.320.0140.00516.34
8.1.310.0040.01118.46
8.1.300.0030.01516.14
8.1.290.0040.00430.84
8.1.280.0090.00925.92
8.1.270.0030.00522.04
8.1.260.0060.00326.35
8.1.250.0040.00428.09
8.1.240.0040.00724.02
8.1.230.0090.00322.11
8.1.220.0030.00617.77
8.1.210.0040.00418.77
8.1.200.0040.00817.48
8.1.190.0000.00817.47
8.1.180.0080.00318.10
8.1.170.0030.00518.70
8.1.160.0000.00719.03
8.1.150.0050.00318.91
8.1.140.0000.00819.73
8.1.130.0040.00419.04
8.1.120.0040.00417.74
8.1.110.0080.00017.67
8.1.100.0040.00417.67
8.1.90.0030.00617.59
8.1.80.0040.00417.67
8.1.70.0040.00417.68
8.1.60.0040.00417.64
8.1.50.0040.00417.69
8.1.40.0040.00417.55
8.1.30.0040.00417.88
8.1.20.0030.00617.83
8.1.10.0050.00317.74
8.1.00.0040.00417.71
8.0.300.0100.00018.77
8.0.290.0040.00417.00
8.0.280.0040.00418.55
8.0.270.0050.00317.29
8.0.260.0000.01017.25
8.0.250.0000.00817.09
8.0.240.0070.00017.18
8.0.230.0050.00317.23
8.0.220.0000.00716.99
8.0.210.0000.00717.12
8.0.200.0030.00317.22
8.0.190.0030.00617.12
8.0.180.0000.00717.04
8.0.170.0050.00217.16
8.0.160.0000.00717.05
8.0.150.0050.00316.96
8.0.140.0050.00316.94
8.0.130.0000.00613.54
8.0.120.0040.00417.11
8.0.110.0080.00017.19
8.0.100.0000.00817.19
8.0.90.0080.00017.00
8.0.80.0100.01317.18
8.0.70.0040.00417.03
8.0.60.0050.00317.09
8.0.50.0040.00417.11
8.0.30.0110.00717.31
8.0.20.0100.00917.42
8.0.10.0000.00817.20
8.0.00.0120.00616.96
7.4.330.0060.00015.55
7.4.320.0030.00516.65
7.4.300.0030.00316.78
7.4.290.0090.00016.53
7.4.280.0030.00616.67
7.4.270.0070.00016.74
7.4.260.0000.00716.77
7.4.250.0070.00016.66
7.4.240.0050.00316.68
7.4.230.0000.00716.80
7.4.220.0100.00716.87
7.4.210.0070.01016.74
7.4.200.0060.00316.47
7.4.160.0100.00716.57
7.4.150.0030.01817.40
7.4.140.0130.00917.86
7.4.130.0040.01516.90
7.4.120.0120.01216.79
7.4.110.0070.01516.73
7.4.100.0140.01116.80
7.4.90.0170.00416.64
7.4.80.0100.00919.39
7.4.70.0080.01316.70
7.4.60.0100.00616.68
7.4.50.0090.00216.59
7.4.40.0040.01916.62
7.4.30.0070.01616.60
7.4.00.0080.00415.09
7.3.330.0050.00013.21
7.3.320.0000.00513.31
7.3.310.0030.00516.48
7.3.300.0080.00016.49
7.3.290.0030.00316.40
7.3.280.0080.00916.48
7.3.270.0130.00717.40
7.3.260.0070.01116.60
7.3.250.0160.00416.64
7.3.240.0070.01216.56
7.3.230.0030.01416.57
7.3.210.0030.01416.55
7.3.200.0120.00616.63
7.3.190.0090.00916.55
7.3.180.0000.01716.48
7.3.170.0040.01316.71
7.3.160.0140.00416.48
7.2.330.0110.01417.04
7.2.320.0090.00917.05
7.2.310.0060.01217.10
7.2.300.0130.00716.82
7.2.290.0070.01117.08
7.2.80.0060.00316.82
7.2.60.0070.00417.29
7.2.50.0040.01117.17
7.1.200.0000.01315.68
7.1.70.0520.01415.53
7.1.60.0640.01533.45
7.1.50.0500.01933.29
7.1.40.0600.01332.71
7.1.30.0590.01932.62
7.1.20.0420.01832.88
7.1.10.0240.01415.05
7.1.00.0290.01815.24
7.0.200.0360.01515.07
7.0.190.0360.01914.82
7.0.180.0360.01114.64
7.0.170.0340.01614.62
7.0.160.0380.01714.81
7.0.150.0200.01314.55
7.0.140.0450.01314.75
7.0.130.0440.00814.76
7.0.120.0340.02315.09
7.0.110.0400.01214.59
7.0.100.0300.01314.72
7.0.90.0300.01414.69
7.0.80.0330.01614.62
7.0.70.0440.01114.68
7.0.60.0890.01614.47
7.0.50.0370.01514.92
7.0.40.0350.00614.77
7.0.30.0300.01014.87
7.0.20.0310.01614.72
7.0.10.0410.01414.66
7.0.00.0230.01214.54

preferences:
149.66 ms | 403 KiB | 5 Q