3v4l.org

run code in 300+ PHP versions simultaneously
<?php function delete(array &$array, string $key): bool { // process the parts $target =& $array; // split the key in it's parts $key_parts = explode('.', $key); while (true) { // check if this key exists, and bail out if it doesn't if ( ! array_key_exists($key_parts[0], $target)) { return false; } // last key component? if (count($key_parts) === 1) { // delete the target found unset($target[$key_parts[0]]); return true; } // change the target $target =& $target[$key_parts[0]]; // and on to the next key part array_shift($key_parts); } } $arr = array('a' => array('b1' => array('c1' => 'value c1', 'c2' => 'value c2'), 'b2' => 'value b2')); var_dump(delete($arr, 'a.b1.c1'), $arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZDAl5
function name:  (null)
number of ops:  10
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, <array>
   37     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'delete'
          3        SEND_REF                                                 !0
          4        SEND_VAL                                                 'a.b1.c1'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function delete:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 9
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 9
Branch analysis from position: 27
Branch analysis from position: 9
filename:       /in/ZDAl5
function name:  delete
number of ops:  29
compiled vars:  !0 = $array, !1 = $key, !2 = $target, !3 = $key_parts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ASSIGN_REF                                               !2, !0
    9     3        INIT_FCALL                                               'explode'
          4        SEND_VAL                                                 '.'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !3, $5
   11     8      > JMP                                                      ->26
   14     9    >   FETCH_DIM_R                                      ~7      !3, 0
         10        ARRAY_KEY_EXISTS                                 ~8      ~7, !2
         11        BOOL_NOT                                         ~9      ~8
         12      > JMPZ                                                     ~9, ->14
   16    13    > > RETURN                                                   <false>
   20    14    >   COUNT                                            ~10     !3
         15        IS_IDENTICAL                                             ~10, 1
         16      > JMPZ                                                     ~11, ->20
   23    17    >   FETCH_DIM_R                                      ~12     !3, 0
         18        UNSET_DIM                                                !2, ~12
   24    19      > RETURN                                                   <true>
   28    20    >   FETCH_DIM_R                                      ~13     !3, 0
         21        FETCH_DIM_W                                      $14     !2, ~13
         22        ASSIGN_REF                                               !2, $14
   31    23        INIT_FCALL                                               'array_shift'
         24        SEND_REF                                                 !3
         25        DO_ICALL                                                 
   11    26    > > JMPNZ                                                    <true>, ->9
   33    27    >   VERIFY_RETURN_TYPE                                       
         28      > RETURN                                                   null

End of function delete

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.67 ms | 1394 KiB | 20 Q