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"; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 14
Branch analysis from position: 42
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 56
Branch analysis from position: 47
2 jumps found. (Code = 78) Position 1 = 48, Position 2 = 56
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 23
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 14
Branch analysis from position: 42
Branch analysis from position: 14
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 32
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 23
Branch analysis from position: 35
Branch analysis from position: 23
Branch analysis from position: 32
Branch analysis from position: 9
filename:       /in/Fgsi9
function name:  (null)
number of ops:  58
compiled vars:  !0 = $correctAnswers, !1 = $submittedStudentData, !2 = $s_data, !3 = $index, !4 = $c, !5 = $studentData, !6 = $studentId, !7 = $totalResult, !8 = $i, !9 = $x, !10 = $r, !11 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    7     1        ASSIGN                                                   !1, <array>
   12     2        TYPE_CHECK                                  128  ~14     !1
          3        BOOL_NOT                                         ~15     ~14
          4      > JMPZ                                                     ~15, ->9
   14     5    >   INIT_FCALL                                               'json_decode'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $16     
          8        ASSIGN                                                   !1, $16
   17     9    >   ASSIGN                                                   !2, <array>
   18    10        ASSIGN                                                   !3, 0
         11        COUNT                                            ~20     !1
         12        ASSIGN                                                   !4, ~20
         13      > JMP                                                      ->40
   21    14    >   FETCH_DIM_R                                      ~22     !1, !3
         15        ASSIGN                                                   !5, ~22
   24    16        FETCH_DIM_R                                      ~24     !5, 0
         17        ASSIGN                                                   !6, ~24
   28    18        ASSIGN                                                   !7, 0
   31    19        ASSIGN                                                   !8, 2
         20        COUNT                                            ~28     !5
         21        ASSIGN                                                   !9, ~28
         22      > JMP                                                      ->33
   33    23    >   FETCH_DIM_R                                      ~30     !5, !8
         24        CAST                                          4  ~31     ~30
         25        SUB                                              ~32     !8, 2
         26        FETCH_DIM_R                                      ~33     !0, ~32
         27        FETCH_DIM_R                                      ~34     ~33, 'value'
         28        CAST                                          4  ~35     ~34
         29        IS_IDENTICAL                                             ~31, ~35
         30      > JMPZ                                                     ~36, ->32
   35    31    >   PRE_INC                                                  !7
   31    32    >   PRE_INC                                                  !8
         33    >   IS_SMALLER                                               !8, !9
         34      > JMPNZ                                                    ~39, ->23
   39    35    >   INIT_ARRAY                                       ~41     !6, 'studentId'
         36        ADD_ARRAY_ELEMENT                                ~41     !7, 'scores'
         37        ASSIGN_DIM                                               !2
         38        OP_DATA                                                  ~41
   18    39        PRE_INC                                                  !3
         40    >   IS_SMALLER                                               !3, !4
         41      > JMPNZ                                                    ~43, ->14
   45    42    >   INIT_FCALL                                               'array_reverse'
         43        SEND_VAR                                                 !2
         44        DO_ICALL                                         $44     
         45        ASSIGN                                                   !10, $44
   47    46      > FE_RESET_R                                       $46     !10, ->56
         47    > > FE_FETCH_R                                               $46, !11, ->56
   49    48    >   FETCH_DIM_R                                      ~47     !11, 'studentId'
         49        CONCAT                                           ~48     'Student+with+roll+number+', ~47
         50        CONCAT                                           ~49     ~48, '+scores+'
         51        FETCH_DIM_R                                      ~50     !11, 'scores'
         52        CONCAT                                           ~51     ~49, ~50
         53        CONCAT                                           ~52     ~51, '%0A'
         54        ECHO                                                     ~52
   47    55      > JMP                                                      ->47
         56    >   FE_FREE                                                  $46
   52    57      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.57 ms | 1008 KiB | 15 Q