3v4l.org

run code in 300+ PHP versions simultaneously
<?php function moveKeyBefore($arr, $find, $move) { if (!isset($arr[$find], $arr[$move])) { return $arr; } $elem = [$move=>$arr[$move]]; // cache the element to be moved $start = array_splice($arr, 0, array_search($find, array_keys($arr))); unset($start[$move]); // only important if $move is in $start return $start + $elem + $arr; } $arr = ['foo1'=>'bar', 'foo2'=>'buzz', 'foo3'=>'bazz']; var_export(moveKeyBefore($arr, 'foo3', 'foo1'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hefOi
function name:  (null)
number of ops:  10
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'var_export'
          2        INIT_FCALL                                               'movekeybefore'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'foo3'
          5        SEND_VAL                                                 'foo1'
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function movekeybefore:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/hefOi
function name:  moveKeyBefore
number of ops:  31
compiled vars:  !0 = $arr, !1 = $find, !2 = $move, !3 = $elem, !4 = $start
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    3     3        ISSET_ISEMPTY_DIM_OBJ                         0  ~5      !0, !1
          4      > JMPZ_EX                                          ~5      ~5, ->7
          5    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~6      !0, !2
          6        BOOL                                             ~5      ~6
          7    >   BOOL_NOT                                         ~7      ~5
          8      > JMPZ                                                     ~7, ->10
    4     9    > > RETURN                                                   !0
    7    10    >   FETCH_DIM_R                                      ~8      !0, !2
         11        INIT_ARRAY                                       ~9      ~8, !2
         12        ASSIGN                                                   !3, ~9
    8    13        INIT_FCALL                                               'array_splice'
         14        SEND_REF                                                 !0
         15        SEND_VAL                                                 0
         16        INIT_FCALL                                               'array_search'
         17        SEND_VAR                                                 !1
         18        INIT_FCALL                                               'array_keys'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $11     
         21        SEND_VAR                                                 $11
         22        DO_ICALL                                         $12     
         23        SEND_VAR                                                 $12
         24        DO_ICALL                                         $13     
         25        ASSIGN                                                   !4, $13
    9    26        UNSET_DIM                                                !4, !2
   10    27        ADD                                              ~15     !4, !3
         28        ADD                                              ~16     ~15, !0
         29      > RETURN                                                   ~16
   11    30*     > RETURN                                                   null

End of function movekeybefore

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.78 ms | 1407 KiB | 22 Q