3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tree = array( array ( 'id' => 1, 'structure' => 1, 'parent' => 0, 'slug' => 'medicinskaya-ge', 'child' => array ( 2 => array ( 'id' => 2, 'structure' => 1.1, 'parent' => 1, 'slug' => 'dnk-diagnostika', 'child' => array ( 3 => array ( 'id' => 3, 'structure' => '1.1.1', 'parent' => 2, 'slug' => 'dnk-diagnostika', 'datafile' => 'ssz', 'template' => 'ssz', ), 4 => array ( 'id' => 4, 'structure' => '1.1.2', 'parent' => 2, 'slug' => 'dnk-diagnostika', 'child' => array ( 5 => array ( 'id' => 5, 'structure' => '1.1.2.1', 'parent' => 4, 'slug' => 'dnk-diagnostika', ), 6 => array ( 'id' => 6, 'structure' => '1.1.2.2', 'parent' => 4, 'slug' => 'testirovanie-ge', ), 7 => array ( 'id' => 7, 'structure' => '1.1.2.3', 'parent' => 4, 'slug' => 'dnk-diagnostika', ), ), ), 8 => array ( 'id' => 8, 'structure' => '1.1.3', 'parent' => 2, 'slug' => 'dnk-diagnostika', ), 9 => array ( 'id' => 9, 'structure' => '1.1.4', 'parent' => 2, 'slug' => 'texnologiya-kol', ), ), ), ), ) ); function getSlugData(string $slug, array $data): array { foreach ($data as $row) { if ($row['slug'] === $slug) { return $row; } if (isset($row['child'])) { $deeper = getSlugData($slug, $row['child']); if ($deeper) { return $deeper; } } } return []; } var_export( getSlugData('testirovanie-ge', $tree) ); echo "\n---\n"; var_export( getSlugData('texnologiya-kol', $tree) ); echo "\n---\n"; var_export( getSlugData('dnk-diagnostika', $tree) ); echo "\n---\n"; var_export( getSlugData('foo', $tree) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7hgrP
function name:  (null)
number of ops:  33
compiled vars:  !0 = $tree
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   96     1        INIT_FCALL                                               'var_export'
   97     2        INIT_FCALL                                               'getslugdata'
          3        SEND_VAL                                                 'testirovanie-ge'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
   96     7        DO_ICALL                                                 
   99     8        ECHO                                                     '%0A---%0A'
  100     9        INIT_FCALL                                               'var_export'
  101    10        INIT_FCALL                                               'getslugdata'
         11        SEND_VAL                                                 'texnologiya-kol'
         12        SEND_VAR                                                 !0
         13        DO_FCALL                                      0  $4      
         14        SEND_VAR                                                 $4
  100    15        DO_ICALL                                                 
  103    16        ECHO                                                     '%0A---%0A'
  104    17        INIT_FCALL                                               'var_export'
  105    18        INIT_FCALL                                               'getslugdata'
         19        SEND_VAL                                                 'dnk-diagnostika'
         20        SEND_VAR                                                 !0
         21        DO_FCALL                                      0  $6      
         22        SEND_VAR                                                 $6
  104    23        DO_ICALL                                                 
  107    24        ECHO                                                     '%0A---%0A'
  108    25        INIT_FCALL                                               'var_export'
  109    26        INIT_FCALL                                               'getslugdata'
         27        SEND_VAL                                                 'foo'
         28        SEND_VAR                                                 !0
         29        DO_FCALL                                      0  $8      
         30        SEND_VAR                                                 $8
  108    31        DO_ICALL                                                 
  110    32      > RETURN                                                   1

Function getslugdata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 24
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 23
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/7hgrP
function name:  getSlugData
number of ops:  28
compiled vars:  !0 = $slug, !1 = $data, !2 = $row, !3 = $deeper
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   81     2      > FE_RESET_R                                       $4      !1, ->24
          3    > > FE_FETCH_R                                               $4, !2, ->24
   82     4    >   FETCH_DIM_R                                      ~5      !2, 'slug'
          5        IS_IDENTICAL                                             !0, ~5
          6      > JMPZ                                                     ~6, ->10
   83     7    >   VERIFY_RETURN_TYPE                                       !2
          8        FE_FREE                                                  $4
          9      > RETURN                                                   !2
   85    10    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'child'
         11      > JMPZ                                                     ~7, ->23
   86    12    >   INIT_FCALL_BY_NAME                                       'getSlugData'
         13        SEND_VAR_EX                                              !0
         14        CHECK_FUNC_ARG                                           
         15        FETCH_DIM_FUNC_ARG                               $8      !2, 'child'
         16        SEND_FUNC_ARG                                            $8
         17        DO_FCALL                                      0  $9      
         18        ASSIGN                                                   !3, $9
   87    19      > JMPZ                                                     !3, ->23
   88    20    >   VERIFY_RETURN_TYPE                                       !3
         21        FE_FREE                                                  $4
         22      > RETURN                                                   !3
   81    23    > > JMP                                                      ->3
         24    >   FE_FREE                                                  $4
   92    25      > RETURN                                                   <array>
   93    26*       VERIFY_RETURN_TYPE                                       
         27*     > RETURN                                                   null

End of function getslugdata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
272.96 ms | 1012 KiB | 18 Q