3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on r4nqM
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:  12
compiled vars:  !0 = $mapping, !1 = $input2, !2 = $output2
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   4     0  E >   ASSIGN                                                   !0, <array>
  13     1        ASSIGN                                                   !1, <array>
  24     2        NOP                                                      
  39     3        INIT_FCALL                                               'maparray'
         4        SEND_VAR                                                 !0
         5        SEND_VAR                                                 !1
         6        DO_FCALL                                      0  $5      
         7        ASSIGN                                                   !2, $5
  41     8        INIT_FCALL                                               'var_dump'
         9        SEND_VAR                                                 !2
        10        DO_ICALL                                                 
        11      > RETURN                                                   1

Function maparray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 29
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 29
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 28
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 25
Branch analysis from position: 28
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/4Jjlo
function name:  mapArray
number of ops:  32
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, ->29
         4    > > FE_FETCH_R                                       ~7      $6, !3, ->29
         5    >   ASSIGN                                                   !4, ~7
  27     6        INIT_FCALL                                               'array_key_exists'
         7        SEND_VAR                                                 !4
         8        SEND_VAR                                                 !1
         9        DO_ICALL                                         $9      
        10      > JMPZ                                                     $9, ->28
  28    11    >   FETCH_DIM_R                                      $10     !1, !4
        12        TYPE_CHECK                                    7  ~11     $10
        13      > JMPZ                                                     ~11, ->22
  29    14    >   INIT_FCALL_BY_NAME                                       'mapArray'
        15        SEND_VAR_EX                                              !0
        16        FETCH_DIM_FUNC_ARG                               $13     !1, !4
        17        SEND_VAR_EX                                              $13
        18        DO_FCALL                                      0  $14     
        19        ASSIGN_DIM                                               !2, !3
        20        OP_DATA                                                  $14
        21      > JMP                                                      ->28
  31    22    >   IS_EQUAL                                         ~15     !4, 'Name'
        23      > JMPZ                                                     ~15, ->25
        24    >   ECHO                                                     'wfoo'
  32    25    >   FETCH_DIM_R                                      $17     !1, !4
        26        ASSIGN_DIM                                               !2, !3
        27        OP_DATA                                                  $17
        28    > > JMP                                                      ->4
        29    >   FE_FREE                                                  $6
  36    30      > RETURN                                                   !2
  37    31*     > RETURN                                                   null

End of function maparray

Generated using Vulcan Logic Dumper, using php 7.3.0