3v4l.org

run code in 300+ PHP versions simultaneously
<?php $correctAnswers = [ ['name'=> 1, 'value'=> 4], ['name'=> 1, 'value'=> 1] ]; $submittedStudentData =[ [101, 0, 1, 1], [102, 0, 4, 1] ]; 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 } $r = array_reverse($s_data); foreach($r 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.50
8.4.130.0070.00617.82
8.4.120.0100.01020.49
8.4.110.0080.00322.21
8.4.100.0110.01018.67
8.4.90.0140.00618.99
8.4.80.0110.00918.69
8.4.70.0110.01317.94
8.4.60.0070.01418.77
8.4.50.0040.00517.77
8.4.40.0030.01619.43
8.4.30.0170.00320.46
8.4.20.0100.01017.68
8.4.10.0190.00018.58
8.3.270.0080.01216.56
8.3.260.0120.00616.59
8.3.250.0090.01019.09
8.3.240.0080.00517.25
8.3.230.0120.00716.60
8.3.220.0110.00718.92
8.3.210.0130.00716.68
8.3.200.0100.00416.79
8.3.190.0050.00417.42
8.3.180.0120.00620.69
8.3.170.0100.00016.46
8.3.160.0190.00016.62
8.3.150.0160.00317.02
8.3.140.0000.00916.66
8.3.130.0090.00018.28
8.3.120.0050.00518.92
8.3.110.0150.00320.94
8.3.100.0080.00024.06
8.3.90.0050.00326.77
8.3.80.0000.01018.43
8.3.70.0000.01516.58
8.3.60.0090.00918.18
8.3.50.0090.00618.41
8.3.40.0140.00419.21
8.3.30.0140.00019.21
8.3.20.0000.00724.18
8.3.10.0000.00824.66
8.3.00.0000.00726.16
8.2.290.0090.01020.52
8.2.280.0030.00718.41
8.2.270.0120.00616.77
8.2.260.0040.00416.54
8.2.250.0040.00416.89
8.2.240.0060.00316.99
8.2.230.0060.00322.58
8.2.220.0000.00837.54
8.2.210.0110.00426.77
8.2.200.0090.00018.88
8.2.190.0090.00616.58
8.2.180.0150.00025.92
8.2.170.0080.00819.08
8.2.160.0080.00622.96
8.2.150.0030.00625.66
8.2.140.0040.00424.66
8.2.130.0060.00326.16
8.2.120.0040.00426.16
8.2.110.0060.00321.07
8.2.100.0090.00317.63
8.2.90.0060.00319.14
8.2.80.0030.00517.97
8.2.70.0080.00017.47
8.2.60.0060.00317.93
8.2.50.0040.00418.07
8.2.40.0050.00518.16
8.2.30.0070.00018.05
8.2.20.0030.00520.43
8.2.10.0040.00417.75
8.2.00.0030.00619.18
8.1.330.0100.00821.79
8.1.320.0070.00216.19
8.1.310.0110.00718.03
8.1.300.0050.00320.21
8.1.290.0040.00730.84
8.1.280.0140.00325.92
8.1.270.0030.00522.11
8.1.260.0080.00026.35
8.1.250.0030.01228.09
8.1.240.0000.00920.91
8.1.230.0040.00717.78
8.1.220.0030.00517.77
8.1.210.0000.00818.77
8.1.200.0070.00417.36
8.1.190.0060.00317.23
8.1.180.0000.00818.10
8.1.170.0030.00518.64
8.1.160.0000.00718.80
8.1.150.0040.00418.63
8.1.140.0040.00417.35
8.1.130.0040.00418.89
8.1.120.0000.00717.35
8.1.110.0060.00317.43
8.1.100.0040.00417.44
8.1.90.0030.00517.48
8.1.80.0050.00317.48
8.1.70.0040.00417.36
8.1.60.0030.00517.61
8.1.50.0000.00917.35
8.1.40.0000.00717.41
8.1.30.0290.00417.58
8.1.20.0210.00717.48
8.1.10.0230.00317.48
8.1.00.0200.00817.47
8.0.300.0080.00018.77
8.0.290.0030.00616.63
8.0.280.0040.00418.49
8.0.270.0040.00416.73
8.0.260.0060.00018.38
8.0.250.0040.00416.96
8.0.240.0070.00016.95
8.0.230.0020.00516.95
8.0.220.0040.00416.90
8.0.210.0070.00016.91
8.0.200.0070.00016.84
8.0.190.0000.00816.98
8.0.180.0050.00316.84
8.0.170.0060.00316.80
8.0.160.0050.00516.85
8.0.150.0140.00716.86
8.0.140.0110.00816.87
8.0.130.0220.00016.71
8.0.120.0170.00716.86
8.0.110.0200.00416.93
8.0.100.0190.00416.80
8.0.90.0160.00616.94
8.0.80.0160.00516.78
8.0.70.0130.00916.84
8.0.60.0200.00216.81
8.0.50.0190.00016.68
8.0.30.0180.00416.91
8.0.20.0160.00416.84
8.0.10.0180.00316.88
7.4.330.0040.00415.55
7.4.320.0020.00516.49
7.4.300.0000.00616.45
7.4.290.0000.00816.41
7.4.280.0190.00516.64
7.4.270.0160.00616.44
7.4.260.0190.00416.38
7.4.250.0170.00616.55
7.4.240.0190.00216.58
7.4.230.0220.00216.57
7.4.220.0180.00316.50
7.4.210.0170.00316.43
7.4.200.0150.00416.39
7.4.190.0180.00316.66
7.4.180.0140.00616.46
7.4.160.0160.00316.43
7.4.150.0180.00316.60
7.4.140.0120.00816.54
7.4.130.0140.00516.34
7.4.120.0200.00016.36
7.4.110.0210.00016.32
7.4.100.0160.00616.55
7.4.90.0220.00016.52
7.4.80.0120.00816.33
7.4.70.0100.01016.39
7.4.60.0170.00216.36
7.4.50.0190.00016.28
7.4.40.0110.00716.47
7.4.30.0150.00416.31
7.4.20.0160.00316.28
7.4.10.0170.00316.41
7.4.00.0170.00316.43

preferences:
32.86 ms | 403 KiB | 5 Q