3v4l.org

run code in 300+ PHP versions simultaneously
<?php $structure = [ "a", "b" => [ "b1", "b2" => [ "b21", "b22" ] ] ]; $data = ['A', 'B1', 'B21', 'B22']; function alterKey(&$arr, $data) { foreach ($arr as $key => $val) { if (!is_array($val)) { $data_key = array_search(strtoupper($val), $data); $arr[$val] = $data[$data_key]; unset($arr[$key]); } else { $arr[$key] = alterKey($val, $data); } } ksort($arr); return $arr; } alterKey($structure, $data); echo '<pre>', print_r($structure);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQ7vA
function name:  (null)
number of ops:  12
compiled vars:  !0 = $structure, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, <array>
   32     2        INIT_FCALL                                               'alterkey'
          3        SEND_REF                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0          
   34     6        ECHO                                                     '%3Cpre%3E'
          7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $5      
         10        ECHO                                                     $5
         11      > RETURN                                                   1

Function alterkey:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/IQ7vA
function name:  alterKey
number of ops:  34
compiled vars:  !0 = $arr, !1 = $data, !2 = $val, !3 = $key, !4 = $data_key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2      > FE_RESET_R                                       $5      !0, ->28
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->28
          4    >   ASSIGN                                                   !3, ~6
   19     5        TYPE_CHECK                                  128  ~8      !2
          6        BOOL_NOT                                         ~9      ~8
          7      > JMPZ                                                     ~9, ->21
   20     8    >   INIT_FCALL                                               'array_search'
          9        INIT_FCALL                                               'strtoupper'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $10     
         12        SEND_VAR                                                 $10
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !4, $11
   21    16        FETCH_DIM_R                                      ~14     !1, !4
         17        ASSIGN_DIM                                               !0, !2
         18        OP_DATA                                                  ~14
   22    19        UNSET_DIM                                                !0, !3
         20      > JMP                                                      ->27
   24    21    >   INIT_FCALL_BY_NAME                                       'alterKey'
         22        SEND_VAR_EX                                              !2
         23        SEND_VAR_EX                                              !1
         24        DO_FCALL                                      0  $16     
         25        ASSIGN_DIM                                               !0, !3
         26        OP_DATA                                                  $16
   18    27    > > JMP                                                      ->3
         28    >   FE_FREE                                                  $5
   28    29        INIT_FCALL                                               'ksort'
         30        SEND_REF                                                 !0
         31        DO_ICALL                                                 
   29    32      > RETURN                                                   !0
   30    33*     > RETURN                                                   null

End of function alterkey

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.67 ms | 1407 KiB | 22 Q