3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'website' => [ 'id' => 'one' ], 'children' => [ [ 'website' => [ 'id' => 'one.one' ], 'children' => [ [ 'website' => [ 'id' => 'one.one.one' ], 'children' => [ [ 'website' => [ 'id' => 'one.one.one.one' ], 'children' => [] ], [ 'website' => [ 'id' => 'one.one.one.two' ], 'children' => [] ] ] ], [ 'website' => [ 'id' => 'one.one.two' ], 'children' => [ [ 'website' => [ 'id' => 'one.one.two.one' ], 'children' => [] ], [ 'website' => [ 'id' => 'one.one.two.two' ], 'children' => [] ] ] ] ] ], [ 'website' => [ 'id' => 'one.two' ], 'children' => [ [ 'website' => [ 'id' => 'one.two.one' ], 'children' => [ [ 'website' => [ 'id' => 'one.two.one.one' ], 'children' => [] ], [ 'website' => [ 'id' => 'one.two.one.two' ], 'children' => [] ] ] ], [ 'website' => [ 'id' => 'one.two.two' ], 'children' => [ [ 'website' => [ 'id' => 'one.two.two.one' ], 'children' => [] ], [ 'website' => [ 'id' => 'one.two.two.two' ], 'children' => [] ] ] ] ] ] ] ], [ 'website' => [ 'id' => 'two' ], 'children' => [] ] ]; function delete_entries(&$array, $ids_to_delete) { foreach ($array['children'] as $index => &$child) { if (in_array($child['website']['id'], $ids_to_delete)) { unset($array['children'][$index]); } delete_entries($child, $ids_to_delete); } } $excluded = array('two', 'one.one.two', 'one.two.one'); foreach ($array as $key => &$arr) { if (in_array($arr['website']['id'], $excluded)) { unset($array[$key]); } else { delete_entries($arr, $excluded); } } var_export($array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/fnno7
function name:  (null)
number of ops:  24
compiled vars:  !0 = $array, !1 = $excluded, !2 = $arr, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
  118     1        ASSIGN                                                   !1, <array>
  119     2      > FE_RESET_RW                                      $6      !0, ->19
          3    > > FE_FETCH_RW                                      ~7      $6, !2, ->19
          4    >   ASSIGN                                                   !3, ~7
  120     5        INIT_FCALL                                               'in_array'
          6        FETCH_DIM_R                                      ~9      !2, 'website'
          7        FETCH_DIM_R                                      ~10     ~9, 'id'
          8        SEND_VAL                                                 ~10
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $11     
         11      > JMPZ                                                     $11, ->14
  121    12    >   UNSET_DIM                                                !0, !3
  120    13      > JMP                                                      ->18
  124    14    >   INIT_FCALL                                               'delete_entries'
         15        SEND_REF                                                 !2
         16        SEND_VAR                                                 !1
         17        DO_FCALL                                      0          
  119    18    > > JMP                                                      ->3
         19    >   FE_FREE                                                  $6
  128    20        INIT_FCALL                                               'var_export'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                                 
         23      > RETURN                                                   1

Function delete_entries:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 126) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/fnno7
function name:  delete_entries
number of ops:  22
compiled vars:  !0 = $array, !1 = $ids_to_delete, !2 = $child, !3 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  110     2        FETCH_DIM_W                                      $4      !0, 'children'
          3      > FE_RESET_RW                                      $5      $4, ->20
          4    > > FE_FETCH_RW                                      ~6      $5, !2, ->20
          5    >   ASSIGN                                                   !3, ~6
  111     6        INIT_FCALL                                               'in_array'
          7        FETCH_DIM_R                                      ~8      !2, 'website'
          8        FETCH_DIM_R                                      ~9      ~8, 'id'
          9        SEND_VAL                                                 ~9
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $10     
         12      > JMPZ                                                     $10, ->15
  112    13    >   FETCH_DIM_UNSET                                  $11     !0, 'children'
         14        UNSET_DIM                                                $11, !3
  114    15    >   INIT_FCALL_BY_NAME                                       'delete_entries'
         16        SEND_VAR_EX                                              !2
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0          
  110    19      > JMP                                                      ->4
         20    >   FE_FREE                                                  $5
  116    21      > RETURN                                                   null

End of function delete_entries

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.04 ms | 1013 KiB | 16 Q