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 ( ! empty($key_parts)) { // check if this key exists, and bail out if it doesn't if ( ! array_key_exists($key_parts[0], $target)) { return false; } // change the target $target =& $target[$key_parts[0]]; // and on to the next key part array_shift($key_parts); } // delete the target found unset($target); return true; } $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/r1nX2
function name:  (null)
number of ops:  10
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ASSIGN                                                   !0, <array>
   34     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 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 9
Branch analysis from position: 23
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 = 44) Position 1 = 23, Position 2 = 9
Branch analysis from position: 23
Branch analysis from position: 9
filename:       /in/r1nX2
function name:  delete
number of ops:  27
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                                                      ->20
   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    >   FETCH_DIM_R                                      ~10     !3, 0
         15        FETCH_DIM_W                                      $11     !2, ~10
         16        ASSIGN_REF                                               !2, $11
   23    17        INIT_FCALL                                               'array_shift'
         18        SEND_REF                                                 !3
         19        DO_ICALL                                                 
   11    20    >   ISSET_ISEMPTY_CV                                 ~14     !3
         21        BOOL_NOT                                         ~15     ~14
         22      > JMPNZ                                                    ~15, ->9
   27    23    >   UNSET_CV                                                 !2
   29    24      > RETURN                                                   <true>
   30    25*       VERIFY_RETURN_TYPE                                       
         26*     > RETURN                                                   null

End of function delete

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.16 ms | 1403 KiB | 20 Q