3v4l.org

run code in 500+ PHP versions simultaneously
<?php function interleave($students, $lessons) { $numStudents = count($students); $numLessons = count($lessons); if ( $numLessons >= $numStudents ) { $studentSliceSize = 1; $lessonSliceSize = intdiv($numLessons, $numStudents); } else { $studentSliceSize = intdiv($numStudents, $numLessons); $lessonSliceSize = 1; } $combinedArray = []; $nextStudent = 0; $nextLesson = 0; while ( $nextStudent < $numStudents || $nextLesson < $numLessons ) { $studentSlice = array_slice($students, $nextStudent, $studentSliceSize); array_push($combinedArray, ...$studentSlice); $nextStudent += $studentSliceSize; $lessonSlice = array_slice($lessons, $nextLesson, $lessonSliceSize); array_push($combinedArray, ...$lessonSlice); $nextLesson += $lessonSliceSize; } return $combinedArray; } var_dump(interleave(['John'], ['Maths'])); var_dump(interleave(['John'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary', 'Sarah'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary', 'Sarah', 'David'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary', 'Sarah', 'David', 'Tim'], ['Maths', 'Science'])); var_dump(interleave(['John', 'Mary'], ['Maths', 'Science', 'Music'])); var_dump(interleave(['John', 'Mary'], ['Maths', 'Science', 'Music', 'English']));

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.5.70.0050.00316.71
8.5.60.0120.00816.73
8.5.50.0110.00816.55
8.5.30.0060.00319.27
8.5.20.0090.00819.31
8.5.10.0100.00721.97
8.5.00.0120.01021.93
8.4.210.0060.00421.29
8.4.180.0150.00719.61
8.4.170.0130.00823.87
8.4.160.0160.00923.25
8.4.150.0070.00616.90
8.4.140.0160.00717.71
8.4.130.0070.00617.85
8.4.120.0040.00522.64
8.4.110.0100.00522.79
8.4.100.0040.00517.90
8.4.90.0130.00817.64
8.4.80.0050.00417.81
8.4.70.0080.00617.75
8.4.60.0030.00518.81
8.4.50.0130.00819.39
8.4.40.0100.01017.52
8.4.30.0070.01418.73
8.4.20.0120.00917.96
8.4.10.0060.00322.22
8.3.300.0100.00920.91
8.3.290.0120.01021.00
8.3.280.0110.01020.00
8.3.270.0090.01116.73
8.3.260.0060.00516.84
8.3.250.0150.00518.84
8.3.240.0130.00517.02
8.3.230.0090.01216.39
8.3.220.0070.01117.20
8.3.210.0050.00416.86
8.3.200.0040.00416.58
8.3.190.0100.00917.02
8.3.180.0120.00816.49
8.3.170.0170.00319.05
8.3.160.0090.00918.42
8.3.150.0090.00920.92
8.3.140.0090.00016.66
8.3.130.0060.00318.35
8.3.120.0130.00320.73
8.3.110.0090.00016.46
8.3.100.0060.00316.79
8.3.90.0080.00826.77
8.3.80.0100.00316.63
8.3.70.0080.00816.58
8.3.60.0160.00316.50
8.3.50.0060.01118.07
8.3.40.0070.00720.29
8.3.30.0090.00618.43
8.3.20.0080.00024.18
8.3.10.0080.00024.66
8.3.00.0000.00826.16
8.2.300.0110.00820.52
8.2.290.0110.00820.34
8.2.280.0100.01118.11
8.2.270.0090.00917.43
8.2.260.0090.00018.22
8.2.250.0060.00316.91
8.2.240.0030.00516.96
8.2.230.0150.00020.94
8.2.220.0050.00324.06
8.2.210.0040.00426.77
8.2.200.0060.00318.29
8.2.190.0130.00316.58
8.2.180.0150.00025.92
8.2.170.0040.01118.91
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0040.00426.16
8.2.110.0000.00920.58
8.2.100.0060.00617.91
8.2.90.0000.00820.55
8.2.80.0040.00420.54
8.2.70.0000.00817.50
8.2.60.0090.00018.16
8.2.50.0000.00818.05
8.2.40.0050.00318.28
8.2.30.0040.00418.24
8.2.20.0020.00519.24
8.2.10.0040.00418.05
8.2.00.0000.00819.20
8.1.340.0120.00917.41
8.1.330.0110.00821.86
8.1.320.0100.01116.10
8.1.310.0180.00018.59
8.1.300.0070.01120.33
8.1.290.0060.00330.84
8.1.280.0150.00325.92
8.1.270.0080.00820.60
8.1.260.0070.00326.35
8.1.250.0060.00328.09
8.1.240.0030.00621.02
8.1.230.0080.00420.85
8.1.220.0080.00017.77
8.1.210.0000.00818.91
8.1.200.0090.00017.35
8.1.190.0050.00317.22
8.1.180.0040.00418.10
8.1.170.0050.00317.62
8.1.160.0000.00719.02
8.1.150.0000.00818.66
8.1.140.0080.00017.43
8.1.130.0070.00019.29
8.1.120.0030.00717.38
8.1.110.0040.00417.48
8.1.100.0000.00717.44
8.1.90.0130.00317.35
8.1.80.0140.00417.46
8.1.70.0050.00917.34
8.1.60.0120.00617.59
8.1.50.0160.00317.54
8.1.40.0140.00517.50
8.1.30.0130.00317.62
8.1.20.0140.00417.56
8.1.10.0110.00717.50
8.1.00.0050.01017.44
8.0.300.0000.00720.13
8.0.290.0030.00516.75
8.0.280.0030.00318.47
8.0.270.0000.00716.88
8.0.260.0000.00716.80
8.0.250.0000.00716.98
8.0.240.0070.00016.91
8.0.230.0080.00316.90
8.0.220.0130.00316.88
8.0.210.0150.00016.76
8.0.200.0120.00416.91
8.0.190.0090.00616.84
8.0.180.0120.00616.94
8.0.170.0120.00616.91
8.0.160.0040.01216.78
8.0.150.0100.00516.79
8.0.140.0110.00516.87
8.0.130.0110.00416.70
8.0.120.0100.00516.90
8.0.110.0120.00216.73
8.0.100.0140.00016.82
8.0.90.0070.00716.85
8.0.80.0070.00716.90
8.0.70.0110.00416.81
8.0.60.0100.00516.70
8.0.50.0110.00516.73
8.0.30.0130.00316.86
8.0.20.0000.01416.89
8.0.10.0120.00417.07
7.4.330.0000.00615.55
7.4.320.0030.00316.67
7.4.300.0120.00316.64
7.4.290.0180.00016.55
7.4.280.0100.00316.53
7.4.270.0170.00016.54
7.4.260.0070.00816.53
7.4.250.0170.00016.49
7.4.240.0120.00416.51
7.4.230.0090.00616.65
7.4.220.0140.00316.46
7.4.210.0050.01116.53
7.4.200.0160.00016.61
7.4.190.0040.01216.73
7.4.180.0110.00416.61
7.4.160.0160.00016.43
7.4.150.0090.00616.50
7.4.140.0110.00416.37
7.4.130.0150.00016.52
7.4.120.0110.00316.45
7.4.110.0160.00016.58
7.4.100.0120.00216.58
7.4.90.0090.00616.47
7.4.80.0110.00416.54
7.4.70.0120.00316.53
7.4.60.0150.00016.56
7.4.50.0100.00416.37
7.4.40.0090.00516.35
7.4.30.0120.00016.56
7.4.20.0040.00816.34
7.4.10.0090.00616.48
7.4.00.0130.00016.46

preferences:
50.83 ms | 1475 KiB | 5 Q