3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ( 60 => array ( 'term_id' => 60, 'name' => 'Vinylbiler', 'slug' => 'vinylbiler', 'term_group' => 0, 'term_taxonomy_id' => 60, 'taxonomy' => 'toys', 'parent' => 0, 'count' => 2, 'filter' => 'raw', 'children' => array ( 63 => array ( 'term_id' => 63, 'name' => '1:43 serien', 'slug' => '143-serien', 'term_group' => 0, 'term_taxonomy_id' => 63, 'taxonomy' => 'toys', 'parent' => 60, 'count' => 2, 'filter' => 'raw', 'children' => array ( 64 => array ( 'term_id' => 64, 'name' => 'Gul', 'slug' => 'gul', 'term_group' => 0, 'term_taxonomy_id' => 64, 'taxonomy' => 'toys', 'parent' => 63, 'count' => 1, 'filter' => 'raw', 'children' => array ( ), ), 65 => array ( 'term_id' => 65, 'name' => 'Rød', 'slug' => 'rod', 'term_group' => 0, 'term_taxonomy_id' => 65, 'taxonomy' => 'toys', 'parent' => 63, 'count' => 1, 'filter' => 'raw', 'children' => array ( ), ), ), ), ), ) ); function search_array($array, $name) { foreach ($array as $key => $value) { if ($value['name'] == $name) { // found the term. remove any children of this value $value['children'] = array(); return $value; } elseif (is_array($value['children'])) { if (($child = search_array($value['children'], $name)) !== false) { $value['children'] = $child; return $value; } } } return false; } print_r(search_array($array, 'Vinylbiler')); print_r(search_array($array, '1:43 serien')); print_r(search_array($array, 'Rød')); print_r(search_array($array, 'Nick'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UHNNQ
function name:  (null)
number of ops:  30
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   87     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'search_array'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'Vinylbiler'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   88     8        INIT_FCALL                                               'print_r'
          9        INIT_FCALL                                               'search_array'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 '1%3A43+serien'
         12        DO_FCALL                                      0  $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                                 
   89    15        INIT_FCALL                                               'print_r'
         16        INIT_FCALL                                               'search_array'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 'R%C3%B8d'
         19        DO_FCALL                                      0  $6      
         20        SEND_VAR                                                 $6
         21        DO_ICALL                                                 
   90    22        INIT_FCALL                                               'print_r'
         23        INIT_FCALL                                               'search_array'
         24        SEND_VAR                                                 !0
         25        SEND_VAL                                                 'Nick'
         26        DO_FCALL                                      0  $8      
         27        SEND_VAR                                                 $8
         28        DO_ICALL                                                 
         29      > RETURN                                                   1

Function search_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 30
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 29
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 29
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/UHNNQ
function name:  search_array
number of ops:  33
compiled vars:  !0 = $array, !1 = $name, !2 = $value, !3 = $key, !4 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   72     2      > FE_RESET_R                                       $5      !0, ->30
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->30
          4    >   ASSIGN                                                   !3, ~6
   73     5        FETCH_DIM_R                                      ~8      !2, 'name'
          6        IS_EQUAL                                                 !1, ~8
          7      > JMPZ                                                     ~9, ->13
   75     8    >   ASSIGN_DIM                                               !2, 'children'
          9        OP_DATA                                                  <array>
   76    10        FE_FREE                                                  $5
         11      > RETURN                                                   !2
   73    12*       JMP                                                      ->29
   78    13    >   FETCH_DIM_R                                      ~11     !2, 'children'
         14        TYPE_CHECK                                  128          ~11
         15      > JMPZ                                                     ~12, ->29
   79    16    >   INIT_FCALL_BY_NAME                                       'search_array'
         17        CHECK_FUNC_ARG                                           
         18        FETCH_DIM_FUNC_ARG                               $13     !2, 'children'
         19        SEND_FUNC_ARG                                            $13
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0  $14     
         22        ASSIGN                                           ~15     !4, $14
         23        TYPE_CHECK                                  1018          ~15
         24      > JMPZ                                                     ~16, ->29
   80    25    >   ASSIGN_DIM                                               !2, 'children'
         26        OP_DATA                                                  !4
   81    27        FE_FREE                                                  $5
         28      > RETURN                                                   !2
   72    29    > > JMP                                                      ->3
         30    >   FE_FREE                                                  $5
   85    31      > RETURN                                                   <false>
   86    32*     > RETURN                                                   null

End of function search_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.81 ms | 1012 KiB | 18 Q