3v4l.org

run code in 300+ PHP versions simultaneously
<?php $mapping = [ "AccountId" => "id", "Street" => "street_name", "Country" => "country", "Contacts" => "contacts", "Id" => "contact_id", "Name" => "name" ]; $input2 = [ "AccountId" => "18", "Street" => "Some Street 123", "Country" => "England", "Contacts" => [ [ "Id" => "1234", "Name" => "John Doe" ] ] ]; function mapArray($mapping, $input) { $output = []; foreach ($mapping as $from => $to) { if (array_key_exists($from, $input)) { if (is_array($input[$from])) { $output[$to] = mapArray($mapping, $input[$from]); } else { if ($from=="Name") { echo "wfoo";} $output[$to] = $input[$from]; } } } return $output; } $output2 = mapArray($mapping, $input2); var_dump($output2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4Jjlo
function name:  (null)
number of ops:  11
compiled vars:  !0 = $mapping, !1 = $input2, !2 = $output2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   12     1        ASSIGN                                                   !1, <array>
   39     2        INIT_FCALL                                               'maparray'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !2, $5
   41     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function maparray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 27
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 26
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
Branch analysis from position: 26
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/4Jjlo
function name:  mapArray
number of ops:  30
compiled vars:  !0 = $mapping, !1 = $input, !2 = $output, !3 = $to, !4 = $from
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        ASSIGN                                                   !2, <array>
   26     3      > FE_RESET_R                                       $6      !0, ->27
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->27
          5    >   ASSIGN                                                   !4, ~7
   27     6        ARRAY_KEY_EXISTS                                         !4, !1
          7      > JMPZ                                                     ~9, ->26
   28     8    >   FETCH_DIM_R                                      ~10     !1, !4
          9        TYPE_CHECK                                  128          ~10
         10      > JMPZ                                                     ~11, ->20
   29    11    >   INIT_FCALL_BY_NAME                                       'mapArray'
         12        SEND_VAR_EX                                              !0
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $13     !1, !4
         15        SEND_FUNC_ARG                                            $13
         16        DO_FCALL                                      0  $14     
         17        ASSIGN_DIM                                               !2, !3
         18        OP_DATA                                                  $14
         19      > JMP                                                      ->26
   31    20    >   IS_EQUAL                                                 !4, 'Name'
         21      > JMPZ                                                     ~15, ->23
         22    >   ECHO                                                     'wfoo'
   32    23    >   FETCH_DIM_R                                      ~17     !1, !4
         24        ASSIGN_DIM                                               !2, !3
         25        OP_DATA                                                  ~17
   26    26    > > JMP                                                      ->4
         27    >   FE_FREE                                                  $6
   36    28      > RETURN                                                   !2
   37    29*     > RETURN                                                   null

End of function maparray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.56 ms | 1403 KiB | 16 Q