3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, ]; function mangle_array($key_to_remove, $key_to_place_after, array $data) { $tmp_value = $data[$key_to_remove]; $new_data = $data; unset($new_data[$key_to_remove]); $to_place_after_position = array_search($key_to_place_after, array_keys($new_data)); $before = array_slice($new_data, 0, $to_place_after_position + 1); $middle = [$key_to_remove => $tmp_value]; $after = array_slice($new_data, $to_place_after_position + 1); return array_merge($before, $middle, $after); } $data_mangled = mangle_array('b', 'c', $data); var_dump($data_mangled);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d5Iek
function name:  (null)
number of ops:  11
compiled vars:  !0 = $data, !1 = $data_mangled
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   27     1        INIT_FCALL                                               'mangle_array'
          2        SEND_VAL                                                 'b'
          3        SEND_VAL                                                 'c'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !1, $3
   30     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function mangle_array:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d5Iek
function name:  mangle_array
number of ops:  37
compiled vars:  !0 = $key_to_remove, !1 = $key_to_place_after, !2 = $data, !3 = $tmp_value, !4 = $new_data, !5 = $to_place_after_position, !6 = $before, !7 = $middle, !8 = $after
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   13     3        FETCH_DIM_R                                      ~9      !2, !0
          4        ASSIGN                                                   !3, ~9
   14     5        ASSIGN                                                   !4, !2
   16     6        UNSET_DIM                                                !4, !0
   18     7        INIT_FCALL                                               'array_search'
          8        SEND_VAR                                                 !1
          9        INIT_FCALL                                               'array_keys'
         10        SEND_VAR                                                 !4
         11        DO_ICALL                                         $12     
         12        SEND_VAR                                                 $12
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !5, $13
   20    15        INIT_FCALL                                               'array_slice'
         16        SEND_VAR                                                 !4
         17        SEND_VAL                                                 0
         18        ADD                                              ~15     !5, 1
         19        SEND_VAL                                                 ~15
         20        DO_ICALL                                         $16     
         21        ASSIGN                                                   !6, $16
   21    22        INIT_ARRAY                                       ~18     !3, !0
         23        ASSIGN                                                   !7, ~18
   22    24        INIT_FCALL                                               'array_slice'
         25        SEND_VAR                                                 !4
         26        ADD                                              ~20     !5, 1
         27        SEND_VAL                                                 ~20
         28        DO_ICALL                                         $21     
         29        ASSIGN                                                   !8, $21
   24    30        INIT_FCALL                                               'array_merge'
         31        SEND_VAR                                                 !6
         32        SEND_VAR                                                 !7
         33        SEND_VAR                                                 !8
         34        DO_ICALL                                         $23     
         35      > RETURN                                                   $23
   25    36*     > RETURN                                                   null

End of function mangle_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.86 ms | 1407 KiB | 24 Q