3v4l.org

run code in 300+ 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:  22
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        INIT_FCALL                                               'str_replace'
          4        CONCAT                                           ~4      '%22', !1
          5        CONCAT                                           ~5      ~4, '%22%3A'
          6        SEND_VAL                                                 ~5
          7        CONCAT                                           ~6      '%22', !2
          8        CONCAT                                           ~7      ~6, '%22%3A'
          9        SEND_VAL                                                 ~7
         10        INIT_FCALL                                               'json_encode'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $8      
         13        SEND_VAR                                                 $8
         14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !3, $9
    7    16        INIT_FCALL                                               'json_decode'
         17        SEND_VAR                                                 !3
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $11     
         20      > RETURN                                                   $11
    8    21*     > RETURN                                                   null

End of function json_change_key

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
263.25 ms | 1082 KiB | 18 Q