3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( 'Группа' => array( 'Ид' => 'aed92e32-a88d-11e9-b74b-002522d5a8f5', 'Наименование' => '01_ДЛЯ ПРОДАЖ', 'Группы' => array( 'Группа' => array( '10' => array( 'Ид' => '776ea23c-4a7a-11ea-a3ba-002522d5a8f5', 'Наименование' => 'Литература', 'Группы' => array( 'Группа' => array( 'Ид' => 'faa0a831-4b3a-11ea-a3ba-002522d5a8f5', 'Наименование' => 'Журналы учета', ), ), ), ) )) ); function list_items($array, $parent = 0) { $output = array(); if (isset($array['Ид'])) { $array = array($array); } foreach ($array as $arr) { if (!is_array($arr)) echo $arr; $output[] = array('id' => $arr['Ид'], 'name' => $arr['Наименование'], 'parent' => $parent); if (is_array($arr['Группы']['Группа'] ?? NULL)) { $output = array_merge($output, list_items($arr['Группы']['Группа'], $arr['Ид'])); } } return $output; } $items = list_items($array); print_r($items);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jdtNc
function name:  (null)
number of ops:  9
compiled vars:  !0 = $array, !1 = $items
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   38     1        INIT_FCALL                                               'list_items'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   39     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function list_items:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 41
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 41
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 40
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 40
Branch analysis from position: 13
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 7
filename:       /in/jdtNc
function name:  list_items
number of ops:  44
compiled vars:  !0 = $array, !1 = $parent, !2 = $output, !3 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   24     2        ASSIGN                                                   !2, <array>
   25     3        ISSET_ISEMPTY_DIM_OBJ                         0          !0, '%D0%98%D0%B4'
          4      > JMPZ                                                     ~5, ->7
   26     5    >   INIT_ARRAY                                       ~6      !0
          6        ASSIGN                                                   !0, ~6
   28     7    > > FE_RESET_R                                       $8      !0, ->41
          8    > > FE_FETCH_R                                               $8, !3, ->41
   29     9    >   TYPE_CHECK                                  128  ~9      !3
         10        BOOL_NOT                                         ~10     ~9
         11      > JMPZ                                                     ~10, ->13
         12    >   ECHO                                                     !3
   30    13    >   FETCH_DIM_R                                      ~12     !3, '%D0%98%D0%B4'
         14        INIT_ARRAY                                       ~13     ~12, 'id'
         15        FETCH_DIM_R                                      ~14     !3, '%D0%9D%D0%B0%D0%B8%D0%BC%D0%B5%D0%BD%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5'
         16        ADD_ARRAY_ELEMENT                                ~13     ~14, 'name'
         17        ADD_ARRAY_ELEMENT                                ~13     !1, 'parent'
         18        ASSIGN_DIM                                               !2
         19        OP_DATA                                                  ~13
   31    20        FETCH_DIM_IS                                     ~15     !3, '%D0%93%D1%80%D1%83%D0%BF%D0%BF%D1%8B'
         21        FETCH_DIM_IS                                     ~16     ~15, '%D0%93%D1%80%D1%83%D0%BF%D0%BF%D0%B0'
         22        COALESCE                                         ~17     ~16
         23        QM_ASSIGN                                        ~17     null
         24        TYPE_CHECK                                  128          ~17
         25      > JMPZ                                                     ~18, ->40
   32    26    >   INIT_FCALL                                               'array_merge'
         27        SEND_VAR                                                 !2
         28        INIT_FCALL_BY_NAME                                       'list_items'
         29        CHECK_FUNC_ARG                                           
         30        FETCH_DIM_FUNC_ARG                               $19     !3, '%D0%93%D1%80%D1%83%D0%BF%D0%BF%D1%8B'
         31        FETCH_DIM_FUNC_ARG                               $20     $19, '%D0%93%D1%80%D1%83%D0%BF%D0%BF%D0%B0'
         32        SEND_FUNC_ARG                                            $20
         33        CHECK_FUNC_ARG                                           
         34        FETCH_DIM_FUNC_ARG                               $21     !3, '%D0%98%D0%B4'
         35        SEND_FUNC_ARG                                            $21
         36        DO_FCALL                                      0  $22     
         37        SEND_VAR                                                 $22
         38        DO_ICALL                                         $23     
         39        ASSIGN                                                   !2, $23
   28    40    > > JMP                                                      ->8
         41    >   FE_FREE                                                  $8
   35    42      > RETURN                                                   !2
   36    43*     > RETURN                                                   null

End of function list_items

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.28 ms | 1453 KiB | 16 Q