3v4l.org

run code in 300+ PHP versions simultaneously
<?php $staff = array(1,2,3,4,5,6,7,8,9,10); $start = array("11:00", "13:00", "17:00", "17:00", "11:00", "13:30", "16:50", "18:30","17:00", "11:00"); $end = array("21:00", "15:00", "19:00", "19:30", "11:30", "15:10", "18:45", "19:45", "19:00", "11:30"); // 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); //var_dump($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++){ //echo $times[$i] ." " . $i ."\n"; if($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); } } foreach($Alone as $key => &$loner){ if($loner["duration"]==0) unset($Alone[$key]); } 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.130.0120.00917.97
8.4.120.0090.00420.83
8.4.110.0100.00822.38
8.4.100.0120.00417.86
8.4.90.0120.00722.14
8.4.80.0050.00517.94
8.4.70.0130.00817.93
8.4.60.0050.00420.64
8.4.50.0150.00519.82
8.4.40.0110.00719.70
8.4.30.0160.00319.66
8.4.20.0100.01017.71
8.4.10.0000.01119.68
8.3.260.0100.01116.73
8.3.250.0110.00918.98
8.3.240.0080.01119.01
8.3.230.0110.00716.61
8.3.220.0080.01117.44
8.3.210.0110.00818.81
8.3.200.0040.00516.59
8.3.190.0090.01018.91
8.3.180.0120.00516.91
8.3.170.0130.00716.71
8.3.160.0160.00317.10
8.3.150.0040.01517.31
8.3.140.0130.00617.28
8.3.130.0100.00018.84
8.3.120.0040.00420.60
8.3.110.0070.01520.94
8.3.100.0030.01316.67
8.3.90.0130.00726.77
8.3.80.0090.00017.97
8.3.70.0030.01216.88
8.3.60.0150.00416.88
8.3.50.0210.01317.55
8.3.40.0120.00319.01
8.3.30.0130.00318.96
8.3.20.0050.00320.20
8.3.10.0000.00821.94
8.3.00.0050.00319.68
8.2.290.0080.01120.66
8.2.280.0050.00418.51
8.2.270.0110.00716.92
8.2.260.0040.00418.88
8.2.250.0050.00322.46
8.2.240.0060.00318.92
8.2.230.0030.00722.58
8.2.220.0030.00737.54
8.2.210.0040.01126.77
8.2.200.0090.00318.41
8.2.190.0110.00718.67
8.2.180.0130.01016.88
8.2.170.0120.00622.96
8.2.160.0140.00019.16
8.2.150.0080.00024.18
8.2.140.0000.00724.66
8.2.130.0080.00019.27
8.2.120.0040.00426.35
8.2.110.0070.00420.93
8.2.100.0080.00319.63
8.2.90.0030.00618.05
8.2.80.0030.00518.98
8.2.70.0030.00617.88
8.2.60.0090.00018.05
8.2.50.0050.00318.07
8.2.40.0050.00320.07
8.2.30.0070.00018.29
8.2.20.0000.00818.28
8.2.10.0040.00418.11
8.2.00.0000.00818.26
8.1.330.0100.01021.83
8.1.320.0120.00716.53
8.1.310.0040.00417.12
8.1.300.0060.00320.27
8.1.290.0130.00030.84
8.1.280.0070.00725.92
8.1.270.0050.00323.99
8.1.260.0040.00426.35
8.1.250.0000.00728.09
8.1.240.0050.00522.11
8.1.230.0000.01017.89
8.1.220.0040.00417.93
8.1.210.0040.00418.77
8.1.200.0070.00317.60
8.1.190.0050.00317.48
8.1.180.0040.00418.10
8.1.170.0030.00618.59
8.1.160.0000.00718.99
8.1.150.0000.00820.67
8.1.140.0000.00719.61
8.1.130.0000.00718.91
8.1.120.0040.00417.62
8.1.110.0080.00017.71
8.1.100.0030.00517.65
8.1.90.0050.00217.63
8.1.80.0040.00417.63
8.1.70.0070.00317.68
8.1.60.0040.00417.72
8.1.50.0040.00417.66
8.1.40.0000.00817.68
8.1.30.0080.00017.78
8.1.20.0000.00817.75
8.1.10.0070.00317.63
8.1.00.0030.00617.69
8.0.300.0040.00418.77
8.0.290.0030.00517.00
8.0.280.0020.00518.51
8.0.270.0020.00517.28
8.0.260.0000.00718.82
8.0.250.0000.00717.10
8.0.240.0000.00817.23
8.0.230.0030.00717.08
8.0.220.0070.00017.15
8.0.210.0070.00017.02
8.0.200.0060.00017.23
8.0.190.0070.00017.18
8.0.180.0000.00717.16
8.0.170.0040.00417.07
8.0.160.0080.00017.07
8.0.150.0000.00717.16
8.0.140.0000.00817.13
8.0.130.0060.00013.45
8.0.120.0000.00817.03
8.0.110.0000.00816.95
8.0.100.0040.00417.19
8.0.90.0040.00416.99
8.0.80.0040.01617.20
8.0.70.0070.00017.10
8.0.60.0000.00817.11
8.0.50.0000.00717.09
8.0.30.0130.00417.52
8.0.20.0160.00917.41
8.0.10.0040.00417.29
8.0.00.0170.01017.22
7.4.330.0050.00015.55
7.4.320.0000.00716.66
7.4.300.0030.00316.78
7.4.290.0000.00816.66
7.4.280.0000.00816.67
7.4.270.0000.00716.68
7.4.260.0060.00316.57
7.4.250.0030.00316.74
7.4.240.0030.00316.61
7.4.230.0030.00516.75
7.4.220.0030.01716.63
7.4.210.0120.00416.73
7.4.200.0040.00416.78
7.4.160.0070.01016.67
7.4.150.0170.01017.40
7.4.140.0090.01017.86
7.4.130.0030.01616.66
7.4.120.0100.00816.69
7.4.110.0100.00716.67
7.4.100.0120.00616.68
7.4.90.0170.00016.73
7.4.80.0080.00919.39
7.4.70.0070.01016.79
7.4.60.0140.00316.72
7.4.50.0060.01016.60
7.4.40.0060.01216.66
7.4.30.0030.01316.81
7.4.10.0080.00815.04
7.4.00.0070.00815.09
7.3.330.0040.00413.29
7.3.320.0000.00613.40
7.3.310.0030.00316.36
7.3.300.0000.00716.48
7.3.290.0060.01016.55
7.3.280.0080.01016.48
7.3.270.0030.01417.40
7.3.260.0110.00616.59
7.3.250.0140.00416.70
7.3.240.0100.00816.63
7.3.230.0170.00016.52
7.3.210.0070.01116.61
7.3.200.0100.00716.79
7.3.190.0080.00916.59
7.3.180.0100.00716.83
7.3.170.0080.01216.76
7.3.160.0070.01016.60
7.3.130.0090.00615.06
7.3.120.0110.00815.20
7.3.110.0120.00814.97
7.3.100.0110.00215.16
7.3.90.0080.00514.90
7.3.80.0020.01015.09
7.3.70.0050.00814.88
7.3.60.0060.00815.09
7.3.50.0040.01214.88
7.3.40.0080.00615.05
7.3.30.0090.00714.93
7.3.20.0080.00716.90
7.3.10.0070.00816.68
7.3.00.0050.01116.72
7.2.330.0040.01516.92
7.2.320.0100.01616.93
7.2.310.0130.00716.96
7.2.300.0170.00916.75
7.2.290.0140.00716.68
7.2.260.0030.01615.49
7.2.250.0070.01015.46
7.2.240.0080.00915.24
7.2.230.0080.00815.37
7.2.220.0070.01015.24
7.2.210.0030.01115.19
7.2.200.0050.01015.21
7.2.190.0020.01415.36
7.2.180.0080.00615.13
7.2.170.0040.01315.21
7.2.160.0040.01415.11
7.2.150.0100.00717.12
7.2.140.0030.01316.91
7.2.130.0040.01317.09
7.2.120.0090.00816.87
7.2.110.0120.00717.01
7.2.100.0110.00516.96
7.2.90.0060.00916.90
7.2.80.0140.00717.04
7.2.70.0090.00616.90
7.2.60.0090.00817.03
7.2.50.0090.00917.02
7.2.40.0080.00916.88
7.2.30.0110.00917.02
7.2.20.0070.00916.78
7.2.10.0120.00917.02
7.2.00.0080.00916.92
7.1.330.0070.01015.73
7.1.320.0040.01015.88
7.1.310.0080.00715.91
7.1.300.0050.00915.79
7.1.290.0070.00715.94
7.1.280.0040.01215.99
7.1.270.0090.00915.95
7.1.260.0060.00915.94
7.1.250.0100.00715.76
7.1.240.0080.00616.04
7.1.230.0090.00616.01
7.1.220.0060.01015.75
7.1.210.0020.01315.93
7.1.200.0090.00815.96
7.1.190.0050.01215.97
7.1.180.0070.00715.79
7.1.170.0060.00815.92
7.1.160.0070.00715.77
7.1.150.0070.00716.02
7.1.140.0070.00815.96
7.1.130.0060.01015.84
7.1.120.0030.01315.91
7.1.110.0040.00915.99
7.1.100.0060.00915.90
7.1.90.0030.00816.04
7.1.80.0080.00815.99
7.1.70.0370.00715.60
7.1.60.0370.01321.80
7.1.50.0420.00521.78
7.1.40.0440.00921.28
7.1.30.0380.00721.67
7.1.20.0380.00921.57
7.1.10.0310.00815.58
7.1.00.0120.00715.60
7.0.330.0090.00615.49
7.0.320.0090.00815.58
7.0.310.0100.00615.28
7.0.300.0030.01115.67
7.0.290.0050.01015.66
7.0.280.0040.01015.48
7.0.270.0060.00615.19
7.0.260.0070.00915.54
7.0.250.0080.00715.51
7.0.240.0080.00615.53
7.0.230.0090.00615.49
7.0.220.0110.00415.61
7.0.210.0060.00915.62
7.0.200.0060.01115.44
7.0.190.0750.00715.36
7.0.180.0130.00515.16
7.0.170.0310.00915.24
7.0.160.0090.00915.31
7.0.150.0070.01015.23
7.0.140.0310.01115.23
7.0.130.0340.00815.42
7.0.120.0280.01315.39
7.0.110.0280.00815.15
7.0.100.0350.00615.16
7.0.90.0320.01915.25
7.0.80.0300.01215.35
7.0.70.0120.00415.24
7.0.60.0340.00815.22
7.0.50.0090.00915.29
7.0.40.0320.00314.01
7.0.30.0260.01114.14
7.0.20.0100.00813.89
7.0.10.0370.00814.02
7.0.00.0280.00413.95
5.6.400.0040.01114.53
5.6.390.0100.01014.48
5.6.380.0070.00514.71
5.6.370.0060.01014.59
5.6.360.0060.01014.18
5.6.350.0040.01314.64
5.6.340.0100.00314.41
5.6.330.0000.01414.22
5.6.320.0070.00714.82
5.6.310.0040.01514.72
5.6.300.0030.01314.48
5.6.290.0060.00914.59
5.6.280.0130.00414.44
5.6.270.0030.00914.47
5.6.260.0120.00014.65
5.6.250.0030.01314.63
5.6.240.0040.01414.88
5.6.230.0030.00714.88
5.6.220.0060.01014.36
5.6.210.0090.00614.39
5.6.200.0060.00914.57
5.6.190.0040.00714.79
5.6.180.0060.00314.67
5.6.170.0090.00614.44
5.6.160.0090.00914.51
5.6.150.0100.00714.51
5.6.140.0120.00314.68
5.6.130.0060.00514.79
5.6.120.0000.01714.56
5.6.110.0040.01114.66
5.6.100.0060.00614.69
5.6.90.0040.01114.52
5.6.80.0050.00514.58
5.6.70.0000.01614.41
5.6.60.0070.00814.43
5.6.50.0060.00914.59
5.6.40.0070.00714.52
5.6.30.0070.00314.38
5.6.20.0070.00714.56
5.6.10.0060.00614.61
5.6.00.0000.01214.70

preferences:
31.91 ms | 403 KiB | 5 Q