3v4l.org

run code in 500+ PHP versions simultaneously
<?php $result = json_decode('[ { "id": "GRP-25", "text": "All Areas", "groupid": 0, "leaf": false, "qtip": "Common", "link": null, "helplink": null, "children": [ { "id": "GRP-25", "text": "All Areas", "groupid": 0, "leaf": true, "qtip": "Common", "link": null, "helplink": null } ] }, { "id": "GRP-25", "text": "All Areas", "groupid": 0, "leaf": false, "qtip": "Common", "link": null, "helplink": null } ]', true); function changeLeafId(array &$data) { foreach ($data as $k => $v) { // recursive call if (is_array($v)) { changeLeafId($data[$k]); continue; } // update 'id' from 'leaf' if ($k == 'id' && $data['leaf'] ?? false) { $data[$k] = 'GRP-' . $v; } } } changeLeafId($result); print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ss584
function name:  (null)
number of ops:  12
compiled vars:  !0 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'json_decode'
          1        SEND_VAL                                                     '%5B%0A++%7B%0A++++%22id%22%3A+%22GRP-25%22%2C%0A++++%22text%22%3A+%22All+Areas%22%2C%0A++++%22groupid%22%3A+0%2C%0A++++%22leaf%22%3A+false%2C%0A++++%22qtip%22%3A+%22Common%22%2C%0A++++%22link%22%3A+null%2C%0A++++%22helplink%22%3A+null%2C%0A++++%22children%22%3A+%5B%0A++++++%7B%0A++++++++%22id%22%3A+%22GRP-25%22%2C%0A++++++++%22text%22%3A+%22All+Areas%22%2C%0A++++++++%22groupid%22%3A+0%2C%0A++++++++%22leaf%22%3A+true%2C%0A++++++++%22qtip%22%3A+%22Common%22%2C%0A++++++++%22link%22%3A+null%2C%0A++++++++%22helplink%22%3A+null%0A++++++%7D%0A++++%5D%0A++%7D%2C%0A++%7B%0A++++%22id%22%3A+%22GRP-25%22%2C%0A++++%22text%22%3A+%22All+Areas%22%2C%0A++++%22groupid%22%3A+0%2C%0A++++%22leaf%22%3A+false%2C%0A++++%22qtip%22%3A+%22Common%22%2C%0A++++%22link%22%3A+null%2C%0A++++%22helplink%22%3A+null%0A++%7D%0A%5D'
   33     2        SEND_VAL                                                     <true>
    3     3        DO_ICALL                                             $1      
          4        ASSIGN                                                       !0, $1
   52     5        INIT_FCALL                                                   'changeleafid'
          6        SEND_REF                                                     !0
          7        DO_FCALL                                          0          
   53     8        INIT_FCALL                                                   'print_r'
          9        SEND_VAR                                                     !0
         10        DO_ICALL                                                     
         11      > RETURN                                                       1

Function changeleafid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 23
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 23
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 22
Branch analysis from position: 16
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/Ss584
function name:  changeLeafId
number of ops:  25
compiled vars:  !0 = $data, !1 = $v, !2 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   RECV                                                 !0      
   37     1      > FE_RESET_R                                           $3      !0, ->23
          2    > > FE_FETCH_R                                           ~4      $3, !1, ->23
          3    >   ASSIGN                                                       !2, ~4
   40     4        TYPE_CHECK                                      128          !1
          5      > JMPZ                                                         ~6, ->12
   41     6    >   INIT_FCALL_BY_NAME                                           'changeLeafId'
          7        CHECK_FUNC_ARG                                               
          8        FETCH_DIM_FUNC_ARG                                   $7      !0, !2
          9        SEND_FUNC_ARG                                                $7
         10        DO_FCALL                                          0          
   42    11      > JMP                                                          ->2
   46    12    >   IS_EQUAL                                             ~9      !2, 'id'
         13      > JMPZ_EX                                              ~9      ~9, ->16
         14    >   FETCH_DIM_R                                          ~10     !0, 'leaf'
         15        BOOL                                                 ~9      ~10
         16    >   COALESCE                                             ~11     ~9
         17        QM_ASSIGN                                            ~11     <false>
         18      > JMPZ                                                         ~11, ->22
   47    19    >   CONCAT                                               ~13     'GRP-', !1
         20        ASSIGN_DIM                                                   !0, !2
         21        OP_DATA                                                      ~13
   37    22    > > JMP                                                          ->2
         23    >   FE_FREE                                                      $3
   50    24      > RETURN                                                       null

End of function changeleafid

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.93 ms | 2062 KiB | 16 Q