3v4l.org

run code in 300+ PHP versions simultaneously
<?php function setTier(array $nodes, $tier = 1) { return array_map(function ($node) use ($tier) { $node->tier = $tier; $node->children = setTier($node->children, $tier + 1); return $node; }, $nodes); } $structure = json_decode(' [{ "name": "a", "children": [{ "name": "c", "children": [{ "name": "e", "children": [{ "name": "g", "children": [] }] }, { "name": "f", "children": [] }] }, { "name": "d", "children": [{ "name": "h", "children": [] }] }] }, { "name": "b", "children": [] }] '); $structure = setTier($structure); print_r($structure); die;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/oCJUV
function name:  (null)
number of ops:  13
compiled vars:  !0 = $structure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%0A++++%5B%7B%0A++++++++%22name%22%3A+%22a%22%2C%0A++++++++%22children%22%3A+%5B%7B%0A++++++++++++%22name%22%3A+%22c%22%2C%0A++++++++++++%22children%22%3A+%5B%7B%0A++++++++++++++++%22name%22%3A+%22e%22%2C%0A++++++++++++++++%22children%22%3A+%5B%7B%0A++++++++++++++++++++%22name%22%3A+%22g%22%2C%0A++++++++++++++++++++%22children%22%3A+%5B%5D%0A++++++++++++++++%7D%5D%0A++++++++++++%7D%2C+%7B%0A++++++++++++++++%22name%22%3A+%22f%22%2C%0A++++++++++++++++%22children%22%3A+%5B%5D%0A++++++++++++%7D%5D%0A++++++++%7D%2C+%7B%0A++++++++++++%22name%22%3A+%22d%22%2C%0A++++++++++++%22children%22%3A+%5B%7B%0A++++++++++++++++%22name%22%3A+%22h%22%2C%0A++++++++++++++++%22children%22%3A+%5B%5D%0A++++++++++++%7D%5D%0A++++++++%7D%5D%0A++++%7D%2C+%7B%0A++++++++%22name%22%3A+%22b%22%2C%0A++++++++%22children%22%3A+%5B%5D%0A++++%7D%5D%0A'
          2        DO_ICALL                                         $1      
          3        ASSIGN                                                   !0, $1
   41     4        INIT_FCALL                                               'settier'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $3      
          7        ASSIGN                                                   !0, $3
   43     8        INIT_FCALL                                               'print_r'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
         11      > EXIT                                                     
   44    12*     > RETURN                                                   1

Function settier:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oCJUV
function name:  setTier
number of ops:  10
compiled vars:  !0 = $nodes, !1 = $tier
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1
    5     2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FoCJUV%3A5%240'
          4        BIND_LEXICAL                                             ~2, !1
   10     5        SEND_VAL                                                 ~2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8      > RETURN                                                   $3
   11     9*     > RETURN                                                   null

End of function settier

Function %00%7Bclosure%7D%2Fin%2FoCJUV%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oCJUV
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $node, !1 = $tier
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    6     2        ASSIGN_OBJ                                               !0, 'tier'
          3        OP_DATA                                                  !1
    7     4        INIT_FCALL_BY_NAME                                       'setTier'
          5        CHECK_FUNC_ARG                                           
          6        FETCH_OBJ_FUNC_ARG                               $4      !0, 'children'
          7        SEND_FUNC_ARG                                            $4
          8        ADD                                              ~5      !1, 1
          9        SEND_VAL_EX                                              ~5
         10        DO_FCALL                                      0  $6      
         11        ASSIGN_OBJ                                               !0, 'children'
         12        OP_DATA                                                  $6
    9    13      > RETURN                                                   !0
   10    14*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FoCJUV%3A5%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.12 ms | 1407 KiB | 20 Q