3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'children' => [ [ 'id' => 123, 'title' => 'test', 'children' => [ [ 'id' => 345, 'title' => 'test 1', 'children' => [], ], [ 'id' => 567, 'title' => 'test 2', 'children' => [ [ 'id' => 789, 'title' => 'test 3', 'children' => [], ], [ 'id' => 333, 'title' => 'tset 4', 'children' => [ [ 'id' => 222, 'title' => 'test 5', 'children' => [], ], [ 'id' => 111, 'title' => 'test 55', 'children' => [], ], [ 'id' => 444, 'title' => 'test 556', 'children' => [], ], [ 'id' => 666, 'title' => 'test44', 'children' => [], ], ], ], [ 'id' => '5556', 'identifier' => 'test 2', 'children' => [ [ 'id' => 888, 'title' => 'test 2', 'children' => [], ], [ 'id' => 255, 'title' => 'tset', 'children' => [], ], [ 'id' => 454, 'title' => 'warm-up-5837', 'children' => [], ], ], ], ], ], ], ], ], ]; function flattenTree(array $tree): array { $flat = []; foreach ($tree['children'] ?? [] as $child) { $flat[] = array_filter($child, 'is_scalar'); if (!empty($child['children'])) { array_push($flat, ...flattenTree($child, $flat)); } } return $flat; } var_export(flattenTree($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gqLEb
function name:  (null)
number of ops:  8
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   88     1        INIT_FCALL                                               'var_export'
          2        INIT_FCALL                                               'flattentree'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function flattentree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 26
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 26
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 25
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/gqLEb
function name:  flattenTree
number of ops:  31
compiled vars:  !0 = $tree, !1 = $flat, !2 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
   79     1        ASSIGN                                                   !1, <array>
   80     2        FETCH_DIM_IS                                     ~4      !0, 'children'
          3        COALESCE                                         ~5      ~4
          4        QM_ASSIGN                                        ~5      <array>
          5      > FE_RESET_R                                       $6      ~5, ->26
          6    > > FE_FETCH_R                                               $6, !2, ->26
   81     7    >   INIT_FCALL                                               'array_filter'
          8        SEND_VAR                                                 !2
          9        SEND_VAL                                                 'is_scalar'
         10        DO_ICALL                                         $8      
         11        ASSIGN_DIM                                               !1
         12        OP_DATA                                                  $8
   82    13        ISSET_ISEMPTY_DIM_OBJ                         1  ~9      !2, 'children'
         14        BOOL_NOT                                         ~10     ~9
         15      > JMPZ                                                     ~10, ->25
   83    16    >   INIT_FCALL                                               'array_push'
         17        SEND_REF                                                 !1
         18        INIT_FCALL_BY_NAME                                       'flattenTree'
         19        SEND_VAR_EX                                              !2
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0  $11     
         22        SEND_UNPACK                                              $11
         23        CHECK_UNDEF_ARGS                                         
         24        DO_ICALL                                                 
   80    25    > > JMP                                                      ->6
         26    >   FE_FREE                                                  $6
   86    27        VERIFY_RETURN_TYPE                                       !1
         28      > RETURN                                                   !1
   87    29*       VERIFY_RETURN_TYPE                                       
         30*     > RETURN                                                   null

End of function flattentree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.58 ms | 1014 KiB | 17 Q