3v4l.org

run code in 300+ PHP versions simultaneously
<?php $links = array( null => array(1, 2, 3, 4, 5), 2 => array(6, 7, 8, 9), 3 => array(10, 11), 10 => array(12), 12 => array(13) ); $nodes = array( 1 => array( "title" => 1, ), 2 => array( "title" => 2, ), 3 => array( "title" => 3, ), 4 => array( "title" => 4, ), 5 => array( "title" => 5, ), 6 => array( "title" => 6, ), 7 => array( "title" => 7, ), 8 => array( "title" => 8, ), 9 => array( "title" => 9, ), 10 => array( "title" => 10, ), 11 => array( "title" => 11, ), 12 => array( "title" => 12, ), 13 => array( "title" => 13, ), ); function f($node, $nodes, $links) { if (!isset($nodes[$node]["children"])) { $nodes[$node]["children"] = array(); } if (isset($links[$node])) { foreach($links[$node] as $child) { array_push($nodes[$node]["children"], f($child)); } } return $nodes[$node]; } f(null); print_r($nodes[null]["children"]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M0skj
function name:  (null)
number of ops:  11
compiled vars:  !0 = $links, !1 = $nodes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   68     2        INIT_FCALL                                               'f'
          3        SEND_VAL                                                 null
          4        DO_FCALL                                      0          
   70     5        INIT_FCALL                                               'print_r'
          6        FETCH_DIM_R                                      ~5      !1, null
          7        FETCH_DIM_R                                      ~6      ~5, 'children'
          8        SEND_VAL                                                 ~6
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function f:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 26
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 26
Branch analysis from position: 10
filename:       /in/M0skj
function name:  f
number of ops:  29
compiled vars:  !0 = $node, !1 = $nodes, !2 = $links, !3 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   55     3        FETCH_DIM_IS                                     ~4      !1, !0
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~5      ~4, 'children'
          5        BOOL_NOT                                         ~6      ~5
          6      > JMPZ                                                     ~6, ->10
   56     7    >   FETCH_DIM_W                                      $7      !1, !0
          8        ASSIGN_DIM                                               $7, 'children'
          9        OP_DATA                                                  <array>
   59    10    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, !0
         11      > JMPZ                                                     ~9, ->26
   60    12    >   FETCH_DIM_R                                      ~10     !2, !0
         13      > FE_RESET_R                                       $11     ~10, ->25
         14    > > FE_FETCH_R                                               $11, !3, ->25
   61    15    >   INIT_FCALL                                               'array_push'
         16        FETCH_DIM_W                                      $12     !1, !0
         17        FETCH_DIM_W                                      $13     $12, 'children'
         18        SEND_REF                                                 $13
         19        INIT_FCALL_BY_NAME                                       'f'
         20        SEND_VAR_EX                                              !3
         21        DO_FCALL                                      0  $14     
         22        SEND_VAR                                                 $14
         23        DO_ICALL                                                 
   60    24      > JMP                                                      ->14
         25    >   FE_FREE                                                  $11
   65    26    >   FETCH_DIM_R                                      ~16     !1, !0
         27      > RETURN                                                   ~16
   66    28*     > RETURN                                                   null

End of function f

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.94 ms | 1403 KiB | 18 Q