3v4l.org

run code in 300+ PHP versions simultaneously
<?php $classType = [ ["class" => "1", "type" => "A"], ["class" => "2", "type" => "A"], ["class" => "3", "type" => "B"] ]; $clollege['studentDetails'] = [ ["grade" => "2", "hobbies" => ["A" , "B"] ], ["grade" => "2", "hobbies" => ["A" ] ], ["grade" => "3", "hobbies" => [ "C" ] ] ]; foreach($clollege['studentDetails'] as $key => &$val){ $grade = $val['grade']; $val['type'] = array_reduce($classType, function($r, $item) use ($grade){ return ($item['class'] == $grade) ? $item['type'] : $r; }); } print_r($clollege);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 126) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/5HGLk
function name:  (null)
number of ops:  23
compiled vars:  !0 = $classType, !1 = $clollege, !2 = $val, !3 = $key, !4 = $grade
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN_DIM                                               !1, 'studentDetails'
   10     2        OP_DATA                                                  <array>
   16     3        FETCH_DIM_W                                      $7      !1, 'studentDetails'
          4      > FE_RESET_RW                                      $8      $7, ->18
          5    > > FE_FETCH_RW                                      ~9      $8, !2, ->18
          6    >   ASSIGN                                                   !3, ~9
   17     7        FETCH_DIM_R                                      ~11     !2, 'grade'
          8        ASSIGN                                                   !4, ~11
   18     9        INIT_FCALL                                               'array_reduce'
         10        SEND_VAR                                                 !0
         11        DECLARE_LAMBDA_FUNCTION                          ~14     [0]
         12        BIND_LEXICAL                                             ~14, !4
   20    13        SEND_VAL                                                 ~14
   18    14        DO_ICALL                                         $15     
         15        ASSIGN_DIM                                               !2, 'type'
   20    16        OP_DATA                                                  $15
   16    17      > JMP                                                      ->5
         18    >   FE_FREE                                                  $8
   23    19        INIT_FCALL                                               'print_r'
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                                 
         22      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5HGLk
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $r, !1 = $item, !2 = $grade
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   19     3        FETCH_DIM_R                                      ~3      !1, 'class'
          4        IS_EQUAL                                                 !2, ~3
          5      > JMPZ                                                     ~4, ->9
          6    >   FETCH_DIM_R                                      ~5      !1, 'type'
          7        QM_ASSIGN                                        ~6      ~5
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~6      !0
         10    > > RETURN                                                   ~6
   20    11*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.37 ms | 1011 KiB | 15 Q