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])) { echo $input[$from]; $output[$to] = mapArray($mapping, $input[$from]); } else { echo $input[$from]; $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/r4nqM
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>
   40     2        INIT_FCALL                                               'maparray'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !2, $5
   42     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 = 28
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 28
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 27
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 27
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/r4nqM
function name:  mapArray
number of ops:  31
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, ->28
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->28
          5    >   ASSIGN                                                   !4, ~7
   27     6        ARRAY_KEY_EXISTS                                         !4, !1
          7      > JMPZ                                                     ~9, ->27
   28     8    >   FETCH_DIM_R                                      ~10     !1, !4
          9        TYPE_CHECK                                  128          ~10
         10      > JMPZ                                                     ~11, ->22
   29    11    >   FETCH_DIM_R                                      ~12     !1, !4
         12        ECHO                                                     ~12
   30    13        INIT_FCALL_BY_NAME                                       'mapArray'
         14        SEND_VAR_EX                                              !0
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $14     !1, !4
         17        SEND_FUNC_ARG                                            $14
         18        DO_FCALL                                      0  $15     
         19        ASSIGN_DIM                                               !2, !3
         20        OP_DATA                                                  $15
         21      > JMP                                                      ->27
   32    22    >   FETCH_DIM_R                                      ~16     !1, !4
         23        ECHO                                                     ~16
   33    24        FETCH_DIM_R                                      ~18     !1, !4
         25        ASSIGN_DIM                                               !2, !3
         26        OP_DATA                                                  ~18
   26    27    > > JMP                                                      ->4
         28    >   FE_FREE                                                  $6
   37    29      > RETURN                                                   !2
   38    30*     > RETURN                                                   null

End of function maparray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.78 ms | 1403 KiB | 16 Q