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, true), array($key1 => $value1), array_slice($array, $offset2 + 2, 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/iLAj2
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/iLAj2
function name:  swapOffsets
number of ops:  46
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        SEND_VAR                                                 !2
         30        SEND_VAL                                                 <true>
         31        DO_ICALL                                         $21     
         32        SEND_VAR                                                 $21
   14    33        INIT_ARRAY                                       ~22     !6, !4
         34        SEND_VAL                                                 ~22
   15    35        INIT_FCALL                                               'array_slice'
         36        SEND_VAR                                                 !0
         37        ADD                                              ~23     !2, 2
         38        SEND_VAL                                                 ~23
         39        SEND_VAL                                                 null
         40        SEND_VAL                                                 <true>
         41        DO_ICALL                                         $24     
         42        SEND_VAR                                                 $24
         43        DO_ICALL                                         $25     
         44      > RETURN                                                   $25
   17    45*     > RETURN                                                   null

End of function swapoffsets

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.19 ms | 1403 KiB | 22 Q