3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'entity_id' => 5740, 'parent_id' => 5739, 'label' => 'Sports', 'name' => 'sports', 'children' => [ [ 'entity_id' => 5754, 'parent_id' => 5740, 'label' => 'Badminton', 'name' => 'badminton', 'children' => [ [ 'entity_id' => 5756, 'parent_id' => 5754, 'label' => 'Tournaments', 'name' => 'tournaments', ] ], ] ], ]; function labelSearch(array $array, string $label): array { foreach ($array as $item) { if ($item['label'] === $label) { unset($item['children']); return $item; } if (isset($item['children'])) { $result = labelSearch($item['children'], $label); if ($result) { return $result; } } } return null; } var_export(labelSearch([$array], 'Badminton'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3Y5Qf
function name:  (null)
number of ops:  10
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   42     1        INIT_FCALL                                               'var_export'
          2        INIT_FCALL                                               'labelsearch'
          3        INIT_ARRAY                                       ~2      !0
          4        SEND_VAL                                                 ~2
          5        SEND_VAL                                                 'Badminton'
          6        DO_FCALL                                      0  $3      
          7        SEND_VAR                                                 $3
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function labelsearch:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 24
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/3Y5Qf
function name:  labelSearch
number of ops:  30
compiled vars:  !0 = $array, !1 = $label, !2 = $item, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2      > FE_RESET_R                                       $4      !0, ->25
          3    > > FE_FETCH_R                                               $4, !2, ->25
   28     4    >   FETCH_DIM_R                                      ~5      !2, 'label'
          5        IS_IDENTICAL                                             !1, ~5
          6      > JMPZ                                                     ~6, ->11
   29     7    >   UNSET_DIM                                                !2, 'children'
   30     8        VERIFY_RETURN_TYPE                                       !2
          9        FE_FREE                                                  $4
         10      > RETURN                                                   !2
   32    11    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'children'
         12      > JMPZ                                                     ~7, ->24
   33    13    >   INIT_FCALL_BY_NAME                                       'labelSearch'
         14        CHECK_FUNC_ARG                                           
         15        FETCH_DIM_FUNC_ARG                               $8      !2, 'children'
         16        SEND_FUNC_ARG                                            $8
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0  $9      
         19        ASSIGN                                                   !3, $9
   34    20      > JMPZ                                                     !3, ->24
   35    21    >   VERIFY_RETURN_TYPE                                       !3
         22        FE_FREE                                                  $4
         23      > RETURN                                                   !3
   27    24    > > JMP                                                      ->3
         25    >   FE_FREE                                                  $4
   39    26        VERIFY_RETURN_TYPE                               ~11     null
         27      > RETURN                                                   ~11
   40    28*       VERIFY_RETURN_TYPE                                       
         29*     > RETURN                                                   null

End of function labelsearch

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.81 ms | 1017 KiB | 15 Q