3v4l.org

run code in 300+ PHP versions simultaneously
<?php $list = array( 'ind' => array( 'messagetype' => 'Alert', 'visibility' => 'Public', 'info' => array( 0 => array( 'urgency' => 'Urgent', 'params' => array( 0 => array( 'Name' => 'display', 'value' => '3; top', ), 1 => array( 'Name' => 'level', 'value' => '1; blue', ), ), 'area' => array( 'ard' => 'Bob', 'code' => array( 0 => array( 'Name' => 'Badge', 'value' => 'GSSD154', ), ), ), ), 1 => array( 'messagetype' => 'Information', 'visibility' => 'Private', 'info' => array( 0 => array( 'urgency' => 'Minor', 'params' => array( 0 => array( 'Name' => 'display', 'value' => '1; left', ), 1 => array( 'Name' => 'level', 'value' => '1; red', ), ), 'area' => array( 'ard' => 'Bob', 'code' => array( 0 => array( 'Name' => 'Badge', 'value' => 'GBECS23', ), ), ), ), ), ), ), ), ); function replaceKeys(&$arr) { foreach ($arr as &$v) { if ( !is_array($v) ) continue; $keys = array_keys($v); $count = count($keys); if ( $count < 2 || $keys !== array_flip($keys) || array_keys(array_merge(...$v)) !== ['Name', 'value'] ) { replaceKeys($v); continue; } foreach ($v as $k => &$item) { $item = array_combine(["Name$k", "value$k"], $item); } } } replaceKeys($list); print_r($list);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lsM2E
function name:  (null)
number of ops:  8
compiled vars:  !0 = $list
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   85     1        INIT_FCALL                                               'replacekeys'
          2        SEND_REF                                                 !0
          3        DO_FCALL                                      0          
   86     4        INIT_FCALL                                               'print_r'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function replacekeys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 52
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 52
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 47) Position 1 = 21, Position 2 = 30
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 35
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 35
2 jumps found. (Code = 125) Position 1 = 36, Position 2 = 50
Branch analysis from position: 36
2 jumps found. (Code = 126) Position 1 = 37, Position 2 = 50
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 50
Branch analysis from position: 30
Branch analysis from position: 20
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/lsM2E
function name:  replaceKeys
number of ops:  54
compiled vars:  !0 = $arr, !1 = $v, !2 = $keys, !3 = $count, !4 = $item, !5 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
   65     1      > FE_RESET_RW                                      $6      !0, ->52
          2    > > FE_FETCH_RW                                              $6, !1, ->52
   66     3    >   TYPE_CHECK                                  128  ~7      !1
          4        BOOL_NOT                                         ~8      ~7
          5      > JMPZ                                                     ~8, ->7
   67     6    > > JMP                                                      ->2
   69     7    >   INIT_FCALL                                               'array_keys'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !2, $9
   70    11        COUNT                                            ~11     !2
         12        ASSIGN                                                   !3, ~11
   72    13        IS_SMALLER                                       ~13     !3, 2
         14      > JMPNZ_EX                                         ~13     ~13, ->20
   73    15    >   INIT_FCALL                                               'array_flip'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $14     
         18        IS_NOT_IDENTICAL                                 ~15     !2, $14
         19        BOOL                                             ~13     ~15
         20    > > JMPNZ_EX                                         ~13     ~13, ->30
   74    21    >   INIT_FCALL                                               'array_keys'
         22        INIT_FCALL                                               'array_merge'
         23        SEND_UNPACK                                              !1
         24        CHECK_UNDEF_ARGS                                         
         25        DO_ICALL                                         $16     
         26        SEND_VAR                                                 $16
         27        DO_ICALL                                         $17     
         28        IS_NOT_IDENTICAL                                 ~18     $17, <array>
         29        BOOL                                             ~13     ~18
         30    > > JMPZ                                                     ~13, ->35
   75    31    >   INIT_FCALL_BY_NAME                                       'replaceKeys'
         32        SEND_VAR_EX                                              !1
         33        DO_FCALL                                      0          
   76    34      > JMP                                                      ->2
   79    35    > > FE_RESET_RW                                      $20     !1, ->50
         36    > > FE_FETCH_RW                                      ~21     $20, !4, ->50
         37    >   ASSIGN                                                   !5, ~21
   80    38        INIT_FCALL                                               'array_combine'
         39        NOP                                                      
         40        FAST_CONCAT                                      ~23     'Name', !5
         41        INIT_ARRAY                                       ~24     ~23
         42        NOP                                                      
         43        FAST_CONCAT                                      ~25     'value', !5
         44        ADD_ARRAY_ELEMENT                                ~24     ~25
         45        SEND_VAL                                                 ~24
         46        SEND_VAR                                                 !4
         47        DO_ICALL                                         $26     
         48        ASSIGN                                                   !4, $26
   79    49      > JMP                                                      ->36
         50    >   FE_FREE                                                  $20
   65    51      > JMP                                                      ->2
         52    >   FE_FREE                                                  $6
   83    53      > RETURN                                                   null

End of function replacekeys

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.88 ms | 1009 KiB | 19 Q