3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array('a' => 2, 'b' => 1, 'c' => 4); $first = array(key($array) => current($array)); // Get the first key/value pair array_shift($array); // Remove it from your array echo end($array); die(); $last = array(end($array) => key($array)); // Get the last key/value pair array_pop($array); // Remove it from the array $array = array_merge($last, $array, $first); // Put it back together print_r($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/2OrRI
function name:  (null)
number of ops:  38
compiled vars:  !0 = $array, !1 = $first, !2 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'key'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $4      
          4        INIT_FCALL                                               'current'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $5      
          7        INIT_ARRAY                                       ~6      $5, $4
          8        ASSIGN                                                   !1, ~6
    5     9        INIT_FCALL                                               'array_shift'
         10        SEND_REF                                                 !0
         11        DO_ICALL                                                 
    6    12        INIT_FCALL                                               'end'
         13        SEND_REF                                                 !0
         14        DO_ICALL                                         $9      
         15        ECHO                                                     $9
         16      > EXIT                                                     
    7    17*       INIT_FCALL                                               'end'
         18*       SEND_REF                                                 !0
         19*       DO_ICALL                                         $10     
         20*       INIT_FCALL                                               'key'
         21*       SEND_VAR                                                 !0
         22*       DO_ICALL                                         $11     
         23*       INIT_ARRAY                                       ~12     $11, $10
         24*       ASSIGN                                                   !2, ~12
    8    25*       INIT_FCALL                                               'array_pop'
         26*       SEND_REF                                                 !0
         27*       DO_ICALL                                                 
   10    28*       INIT_FCALL                                               'array_merge'
         29*       SEND_VAR                                                 !2
         30*       SEND_VAR                                                 !0
         31*       SEND_VAR                                                 !1
         32*       DO_ICALL                                         $15     
         33*       ASSIGN                                                   !0, $15
   12    34*       INIT_FCALL                                               'print_r'
         35*       SEND_VAR                                                 !0
         36*       DO_ICALL                                                 
         37*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.31 ms | 1396 KiB | 27 Q