3v4l.org

run code in 300+ PHP versions simultaneously
<?php function swapOffsets(array $array, $offset1, $offset2) { $keys = array_keys($array); $key1 = $keys[$offset1]; $key2 = $keys[$offset2]; $value1 = $array[$key1]; $value2 = $array[$key2]; array_splice($array, $offset1, 1, array($key2 => $value2)); array_splice($array, $offset2, 1, array($key1 => $value1)); return $array; } var_dump(swapOffsets(['a' => 1, 'b' => 2, 'c' => 3], 0, 2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nj47T
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'swapoffsets'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 2
          5        DO_FCALL                                      0  $0      
          6        SEND_VAR                                                 $0
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function swapoffsets:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nj47T
function name:  swapOffsets
number of ops:  31
compiled vars:  !0 = $array, !1 = $offset1, !2 = $offset2, !3 = $keys, !4 = $key1, !5 = $key2, !6 = $value1, !7 = $value2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    4     3        INIT_FCALL                                               'array_keys'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !3, $8
    5     7        FETCH_DIM_R                                      ~10     !3, !1
          8        ASSIGN                                                   !4, ~10
    6     9        FETCH_DIM_R                                      ~12     !3, !2
         10        ASSIGN                                                   !5, ~12
    7    11        FETCH_DIM_R                                      ~14     !0, !4
         12        ASSIGN                                                   !6, ~14
    8    13        FETCH_DIM_R                                      ~16     !0, !5
         14        ASSIGN                                                   !7, ~16
   10    15        INIT_FCALL                                               'array_splice'
         16        SEND_REF                                                 !0
         17        SEND_VAR                                                 !1
         18        SEND_VAL                                                 1
         19        INIT_ARRAY                                       ~18     !7, !5
         20        SEND_VAL                                                 ~18
         21        DO_ICALL                                                 
   11    22        INIT_FCALL                                               'array_splice'
         23        SEND_REF                                                 !0
         24        SEND_VAR                                                 !2
         25        SEND_VAL                                                 1
         26        INIT_ARRAY                                       ~20     !6, !4
         27        SEND_VAL                                                 ~20
         28        DO_ICALL                                                 
   13    29      > RETURN                                                   !0
   14    30*     > RETURN                                                   null

End of function swapoffsets

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.39 ms | 1403 KiB | 20 Q