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]; return array_merge( array_slice($array, 0, $offset1, true), array($key2 => $value2), array_slice($array, $offset1 + 1, $offset2 - $offset1 - 1, true), array($key1 => $value1), array_slice($array, $offset2 + 1, null, true) ); } var_dump(swapOffsets(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5], 1, 3));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P8NpE
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'swapoffsets'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 1
          4        SEND_VAL                                                 3
          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/P8NpE
function name:  swapOffsets
number of ops:  48
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_merge'
   11    16        INIT_FCALL                                               'array_slice'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 0
         19        SEND_VAR                                                 !1
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $18     
         22        SEND_VAR                                                 $18
   12    23        INIT_ARRAY                                       ~19     !7, !5
         24        SEND_VAL                                                 ~19
   13    25        INIT_FCALL                                               'array_slice'
         26        SEND_VAR                                                 !0
         27        ADD                                              ~20     !1, 1
         28        SEND_VAL                                                 ~20
         29        SUB                                              ~21     !2, !1
         30        SUB                                              ~22     ~21, 1
         31        SEND_VAL                                                 ~22
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $23     
         34        SEND_VAR                                                 $23
   14    35        INIT_ARRAY                                       ~24     !6, !4
         36        SEND_VAL                                                 ~24
   15    37        INIT_FCALL                                               'array_slice'
         38        SEND_VAR                                                 !0
         39        ADD                                              ~25     !2, 1
         40        SEND_VAL                                                 ~25
         41        SEND_VAL                                                 null
         42        SEND_VAL                                                 <true>
         43        DO_ICALL                                         $26     
         44        SEND_VAR                                                 $26
         45        DO_ICALL                                         $27     
         46      > RETURN                                                   $27
   17    47*     > RETURN                                                   null

End of function swapoffsets

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.76 ms | 1403 KiB | 22 Q