3v4l.org

run code in 300+ PHP versions simultaneously
<?php function swapOffsets(array $array, $offset1, $offset2) { list($offset1, $offset2) = array(min($offset1, $offset2), max($offset1, $offset2)); return array_merge( array_slice($array, 0, $offset1, true), array_slice($array, $offset2, 1, true), array_slice($array, $offset1 + 1, $offset2 - $offset1 - 1, true), array_slice($array, $offset1, 1, true), 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/9B5Zk
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     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/9B5Zk
function name:  swapOffsets
number of ops:  61
compiled vars:  !0 = $array, !1 = $offset1, !2 = $offset2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    4     3        INIT_FCALL                                               'min'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $3      
          7        INIT_ARRAY                                       ~4      $3
          8        INIT_FCALL                                               'max'
          9        SEND_VAR                                                 !1
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $5      
         12        ADD_ARRAY_ELEMENT                                ~4      $5
         13        FETCH_LIST_R                                     $6      ~4, 0
         14        ASSIGN                                                   !1, $6
         15        FETCH_LIST_R                                     $8      ~4, 1
         16        ASSIGN                                                   !2, $8
         17        FREE                                                     ~4
    6    18        INIT_FCALL                                               'array_merge'
    7    19        INIT_FCALL                                               'array_slice'
         20        SEND_VAR                                                 !0
         21        SEND_VAL                                                 0
         22        SEND_VAR                                                 !1
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $10     
         25        SEND_VAR                                                 $10
    8    26        INIT_FCALL                                               'array_slice'
         27        SEND_VAR                                                 !0
         28        SEND_VAR                                                 !2
         29        SEND_VAL                                                 1
         30        SEND_VAL                                                 <true>
         31        DO_ICALL                                         $11     
         32        SEND_VAR                                                 $11
    9    33        INIT_FCALL                                               'array_slice'
         34        SEND_VAR                                                 !0
         35        ADD                                              ~12     !1, 1
         36        SEND_VAL                                                 ~12
         37        SUB                                              ~13     !2, !1
         38        SUB                                              ~14     ~13, 1
         39        SEND_VAL                                                 ~14
         40        SEND_VAL                                                 <true>
         41        DO_ICALL                                         $15     
         42        SEND_VAR                                                 $15
   10    43        INIT_FCALL                                               'array_slice'
         44        SEND_VAR                                                 !0
         45        SEND_VAR                                                 !1
         46        SEND_VAL                                                 1
         47        SEND_VAL                                                 <true>
         48        DO_ICALL                                         $16     
         49        SEND_VAR                                                 $16
   11    50        INIT_FCALL                                               'array_slice'
         51        SEND_VAR                                                 !0
         52        ADD                                              ~17     !2, 1
         53        SEND_VAL                                                 ~17
         54        SEND_VAL                                                 null
         55        SEND_VAL                                                 <true>
         56        DO_ICALL                                         $18     
         57        SEND_VAR                                                 $18
         58        DO_ICALL                                         $19     
         59      > RETURN                                                   $19
   13    60*     > RETURN                                                   null

End of function swapoffsets

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.33 ms | 1402 KiB | 24 Q