3v4l.org

run code in 500+ PHP versions simultaneously
<?php $var = '[{"player":"Tiger Woods"},{"player":"Gary Player"}]'; $temp = json_decode($var, true); function json_change_key($arr, $oldkey, $newkey) { $json = str_replace('"'.$oldkey.'":', '"'.$newkey.'":', json_encode($arr)); return json_decode($json, true); } $temp = json_change_key($temp, 'player', 'golfer'); print_r($temp);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fmPFd
function name:  (null)
number of ops:  16
compiled vars:  !0 = $var, !1 = $temp
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%5B%7B%22player%22%3A%22Tiger+Woods%22%7D%2C%7B%22player%22%3A%22Gary+Player%22%7D%5D'
    4     1        INIT_FCALL                                                   'json_decode'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     <true>
          4        DO_ICALL                                             $3      
          5        ASSIGN                                                       !1, $3
    9     6        INIT_FCALL                                                   'json_change_key'
          7        SEND_VAR                                                     !1
          8        SEND_VAL                                                     'player'
          9        SEND_VAL                                                     'golfer'
         10        DO_FCALL                                          0  $5      
         11        ASSIGN                                                       !1, $5
   10    12        INIT_FCALL                                                   'print_r'
         13        SEND_VAR                                                     !1
         14        DO_ICALL                                                     
         15      > RETURN                                                       1

Function json_change_key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fmPFd
function name:  json_change_key
number of ops:  19
compiled vars:  !0 = $arr, !1 = $oldkey, !2 = $newkey, !3 = $json
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    6     3        CONCAT                                               ~4      '%22', !1
          4        CONCAT                                               ~5      ~4, '%22%3A'
          5        CONCAT                                               ~6      '%22', !2
          6        CONCAT                                               ~7      ~6, '%22%3A'
          7        INIT_FCALL                                                   'json_encode'
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                             $8      
         10        FRAMELESS_ICALL_3                str_replace         ~9      ~5, ~7
         11        OP_DATA                                                      $8
         12        ASSIGN                                                       !3, ~9
    7    13        INIT_FCALL                                                   'json_decode'
         14        SEND_VAR                                                     !3
         15        SEND_VAL                                                     <true>
         16        DO_ICALL                                             $11     
         17      > RETURN                                                       $11
    8    18*     > RETURN                                                       null

End of function json_change_key

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.92 ms | 2141 KiB | 17 Q