3v4l.org

run code in 300+ PHP versions simultaneously
<?php $var = '[{"player":"Tiger Woods", "wins":"10","losses":"3"},{"player":"Gary Player","wins":"7", "losses":6}]'; $temp = json_decode($var, true); function recursive_change_key($arr, $set) { if (is_array($arr) && is_array($set)) { $newArr = []; foreach ($arr as $k => $v) { $key = array_key_exists($k, $set) ? $set[$k] : $k; $newArr[$key] = is_array($v) ? recursive_change_key($v, $set) : $v; } return $newArr; } return $arr; } $set = [ "player" => "golfers", "wins" => "victories", "losses" => "defeats" ]; $temp = recursive_change_key($temp, $set); print_r($temp);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EmnRT
function name:  (null)
number of ops:  16
compiled vars:  !0 = $var, !1 = $temp, !2 = $set
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%7B%22player%22%3A%22Tiger+Woods%22%2C+%22wins%22%3A%2210%22%2C%22losses%22%3A%223%22%7D%2C%7B%22player%22%3A%22Gary+Player%22%2C%22wins%22%3A%227%22%2C+%22losses%22%3A6%7D%5D'
    4     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
   17     6        ASSIGN                                                   !2, <array>
   22     7        INIT_FCALL                                               'recursive_change_key'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !2
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !1, $7
   23    12        INIT_FCALL                                               'print_r'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Function recursive_change_key:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 32
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 30
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
Branch analysis from position: 26
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/EmnRT
function name:  recursive_change_key
number of ops:  34
compiled vars:  !0 = $arr, !1 = $set, !2 = $newArr, !3 = $v, !4 = $k, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        TYPE_CHECK                                  128  ~6      !0
          3      > JMPZ_EX                                          ~6      ~6, ->6
          4    >   TYPE_CHECK                                  128  ~7      !1
          5        BOOL                                             ~6      ~7
          6    > > JMPZ                                                     ~6, ->32
    8     7    >   ASSIGN                                                   !2, <array>
    9     8      > FE_RESET_R                                       $9      !0, ->30
          9    > > FE_FETCH_R                                       ~10     $9, !3, ->30
         10    >   ASSIGN                                                   !4, ~10
   10    11        ARRAY_KEY_EXISTS                                         !4, !1
         12      > JMPZ                                                     ~12, ->16
         13    >   FETCH_DIM_R                                      ~13     !1, !4
         14        QM_ASSIGN                                        ~14     ~13
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~14     !4
         17    >   ASSIGN                                                   !5, ~14
   11    18        TYPE_CHECK                                  128          !3
         19      > JMPZ                                                     ~17, ->26
         20    >   INIT_FCALL_BY_NAME                                       'recursive_change_key'
         21        SEND_VAR_EX                                              !3
         22        SEND_VAR_EX                                              !1
         23        DO_FCALL                                      0  $18     
         24        QM_ASSIGN                                        ~19     $18
         25      > JMP                                                      ->27
         26    >   QM_ASSIGN                                        ~19     !3
         27    >   ASSIGN_DIM                                               !2, !5
         28        OP_DATA                                                  ~19
    9    29      > JMP                                                      ->9
         30    >   FE_FREE                                                  $9
   13    31      > RETURN                                                   !2
   15    32    > > RETURN                                                   !0
   16    33*     > RETURN                                                   null

End of function recursive_change_key

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.79 ms | 1013 KiB | 16 Q