3v4l.org

run code in 300+ PHP versions simultaneously
<?php $correctAnswers = [ ['name'=> 1, 'value'=> 4], ['name'=> 1, 'value'=> 1], ['name'=> 1, 'value'=> 3], ['name'=> 1, 'value'=> 1], ['name'=> 1, 'value'=> 2] ]; $submittedStudentData =[ [101, 0, 1, 1, 0, 0, 0], [102, 0, 4, 1, 3, 1, 2], [103, 0, 4, 1, 0, 0, 0], [104, 0, 0, 1, 0, 0, 0], [105, 0, 0, 0, 0, 0, 0] ]; if(!is_array($submittedStudentData)) { $submittedStudentData = json_decode($submittedStudentData); } $s_data = []; for ($index = 0, $c = count($submittedStudentData); $index < $c; $index++){ // get each student data $studentData = $submittedStudentData[$index]; // get the student roll number $studentId = $studentData[0]; // initialize the total result with zero pre value $totalResult = 0; // loop through the student's submitted answer for ($i = 2, $x = count($studentData) ; $i < $x; $i++) { if ((int)$studentData[$i] === (int)$correctAnswers[$i - 2]["value"]) { $totalResult++; } } $s_data[] = ['studentId' =>$studentId, 'scores'=>$totalResult]; // final result for this student } usort($s_data, function($k, $v) { return $v['scores'] <=> $k['scores']; }); foreach($s_data as $d) { echo 'Student with roll number '. $d['studentId'] .' scores '. $d['scores']."\n"; } ?>

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.140.0150.00617.74
8.4.130.0140.00617.65
8.4.120.0110.00624.04
8.4.110.0130.00620.57
8.4.100.0090.01118.69
8.4.90.0120.00520.57
8.4.80.0070.00318.73
8.4.70.0140.00620.38
8.4.60.0060.00818.61
8.4.50.0140.00720.36
8.4.40.0100.00619.66
8.4.30.0050.00320.52
8.4.20.0150.00717.86
8.4.10.0030.00718.72
8.3.270.0090.01116.81
8.3.260.0110.00916.82
8.3.250.0040.00416.87
8.3.240.0090.00917.23
8.3.230.0110.01016.80
8.3.220.0100.00818.99
8.3.210.0050.01018.67
8.3.200.0050.00316.86
8.3.190.0070.01318.36
8.3.180.0110.00816.54
8.3.170.0070.01117.12
8.3.160.0070.01116.82
8.3.150.0130.00620.66
8.3.140.0070.00317.09
8.3.130.0000.00818.50
8.3.120.0040.00418.80
8.3.110.0160.00020.94
8.3.100.0160.00324.06
8.3.90.0050.00226.77
8.3.80.0030.00618.55
8.3.70.0090.00616.63
8.3.60.0110.00716.50
8.3.50.0090.00618.36
8.3.40.0170.00419.04
8.3.30.0120.00319.04
8.3.20.0030.01224.18
8.3.10.0140.00024.66
8.3.00.0040.00426.16
8.2.290.0120.00620.58
8.2.280.0110.00916.91
8.2.270.0070.00317.08
8.2.260.0060.00316.50
8.2.250.0100.01016.51
8.2.240.0000.00818.95
8.2.230.0140.00022.58
8.2.220.0060.00337.54
8.2.210.0040.01426.77
8.2.200.0060.00316.75
8.2.190.0070.00718.41
8.2.180.0100.01025.92
8.2.170.0150.00618.82
8.2.160.0230.00622.96
8.2.150.0110.00325.66
8.2.140.0000.00724.66
8.2.130.0050.00226.16
8.2.120.0040.00419.82
8.2.110.0090.00020.36
8.2.100.0120.00017.91
8.2.90.0040.00417.72
8.2.80.0040.00419.11
8.2.70.0000.00817.63
8.2.60.0050.00317.63
8.2.50.0060.00317.98
8.2.40.0030.00518.16
8.2.30.0060.00318.05
8.2.20.0040.00420.36
8.2.10.0070.00317.69
8.2.00.0040.00419.29
8.1.330.0110.00921.89
8.1.320.0110.00916.34
8.1.310.0030.00716.68
8.1.300.0040.00420.09
8.1.290.0030.00630.84
8.1.280.0030.01325.92
8.1.270.0080.00023.99
8.1.260.0000.00826.35
8.1.250.0070.00028.09
8.1.240.0070.00323.76
8.1.230.0080.00320.87
8.1.220.0080.00017.79
8.1.210.0040.00418.77
8.1.200.0050.00317.23
8.1.190.0050.00317.22
8.1.180.0040.00418.10
8.1.170.0040.00417.62
8.1.160.0040.00418.76
8.1.150.0040.00418.55
8.1.140.0000.00717.44
8.1.130.0030.00318.84
8.1.120.0000.00717.33
8.1.110.0040.00417.43
8.1.100.0000.00817.46
8.1.90.0030.00517.45
8.1.80.0040.00417.34
8.1.70.0030.00317.51
8.1.60.0050.00317.47
8.1.50.0000.00817.48
8.1.40.0040.00417.40
8.1.30.0040.00717.66
8.1.20.0070.00517.62
8.1.10.0120.00017.55
8.1.00.0070.00317.41
8.0.300.0040.00420.21
8.0.290.0050.00216.88
8.0.280.0040.00418.43
8.0.270.0030.00316.75
8.0.260.0000.00618.45
8.0.250.0030.00516.95
8.0.240.0000.00717.05
8.0.230.0070.00316.93
8.0.220.0030.00316.87
8.0.210.0040.00416.96
8.0.200.0070.00016.91
8.0.190.0000.01016.84
8.0.180.0050.00216.87
8.0.170.0070.00316.82
8.0.160.0070.00216.90
8.0.150.0080.00516.70
8.0.140.0120.00016.81
8.0.130.0100.00516.77
8.0.120.0140.00316.86
8.0.110.0050.01016.64
8.0.100.0140.00616.81
8.0.90.0180.00016.88
8.0.80.0120.00716.78
8.0.70.0180.00016.87
8.0.60.0170.00016.83
8.0.50.0100.00316.66
8.0.30.0030.00916.67
8.0.20.0100.00316.83
8.0.10.0130.00016.98
7.4.330.0000.00515.55
7.4.320.0030.00316.52
7.4.300.0030.00316.57
7.4.290.0070.00016.54
7.4.280.0070.00716.32
7.4.270.0080.00416.55
7.4.260.0100.00716.48
7.4.250.0180.00416.60
7.4.240.0190.00416.48
7.4.230.0200.00516.52
7.4.220.0160.00616.39
7.4.210.0130.00616.39
7.4.200.0140.00616.57
7.4.190.0160.00416.63
7.4.180.0160.00016.62
7.4.160.0120.00616.53
7.4.150.0110.00516.41
7.4.140.0200.00016.44
7.4.130.0190.00016.44
7.4.120.0120.00616.30
7.4.110.0120.00216.41
7.4.100.0090.00216.48
7.4.90.0160.00016.50
7.4.80.0130.00416.50
7.4.70.0140.00516.51
7.4.60.0170.00416.32
7.4.50.0140.00316.36
7.4.40.0100.00516.31
7.4.30.0100.00316.43
7.4.20.0050.00916.40
7.4.10.0060.00616.48
7.4.00.0160.00016.32

preferences:
32.32 ms | 403 KiB | 5 Q