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"; } ?>
Output for git.master, git.master_jit, rfc.property-hooks
Student with roll number 102 scores 5 Student with roll number 103 scores 2 Student with roll number 101 scores 1 Student with roll number 104 scores 1 Student with roll number 105 scores 0

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
28.99 ms | 405 KiB | 5 Q