3v4l.org

run code in 300+ PHP versions simultaneously
<?php // This code is public domain. The original author is Marc Ermshaus. error_reporting(-1); /** * Circularly shifts an array * * Shifts to right for $steps > 0. Shifts to left for $steps < 0. Keys are * preserved. * * @param array $array Array to shift * @param int $steps Steps to shift array by * @return array Resulting array */ function array_shift_circular(array $array, $steps = 1) { if (!is_int($steps)) { throw new InvalidArgumentException( 'steps has to be an (int)'); } if ($steps === 0) { return $array; } $l = count($array); if ($l === 0) { return $array; } $steps = $steps % $l; $steps *= -1; return array_merge(array_slice($array, $steps), array_slice($array, 0, $steps)); } header('content-type: text/plain'); $a = range(0, 9); $l = count($a); for ($i = $l * -2; $i <= $l * 2; $i++) { printf("% 3s : %s\n", $i, implode(', ', array_shift_circular($a, $i))); } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 16
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 16
Branch analysis from position: 33
Branch analysis from position: 16
filename:       /in/tj59J
function name:  (null)
number of ops:  34
compiled vars:  !0 = $a, !1 = $l, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
   41     3        INIT_FCALL                                               'header'
          4        SEND_VAL                                                 'content-type%3A+text%2Fplain'
          5        DO_ICALL                                                 
   43     6        INIT_FCALL                                               'range'
          7        SEND_VAL                                                 0
          8        SEND_VAL                                                 9
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !0, $5
   45    11        COUNT                                            ~7      !0
         12        ASSIGN                                                   !1, ~7
   47    13        MUL                                              ~9      !1, -2
         14        ASSIGN                                                   !2, ~9
         15      > JMP                                                      ->30
   48    16    >   INIT_FCALL                                               'printf'
         17        SEND_VAL                                                 '%25+3s++%3A++%25s%0A'
         18        SEND_VAR                                                 !2
         19        INIT_FCALL                                               'implode'
         20        SEND_VAL                                                 '%2C+'
         21        INIT_FCALL                                               'array_shift_circular'
         22        SEND_VAR                                                 !0
         23        SEND_VAR                                                 !2
         24        DO_FCALL                                      0  $11     
         25        SEND_VAR                                                 $11
         26        DO_ICALL                                         $12     
         27        SEND_VAR                                                 $12
         28        DO_ICALL                                                 
   47    29        PRE_INC                                                  !2
         30    >   MUL                                              ~15     !1, 2
         31        IS_SMALLER_OR_EQUAL                                      !2, ~15
         32      > JMPNZ                                                    ~16, ->16
   50    33    > > RETURN                                                   1

Function array_shift_circular:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tj59J
function name:  array_shift_circular
number of ops:  35
compiled vars:  !0 = $array, !1 = $steps, !2 = $l
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1
   17     2        TYPE_CHECK                                   16  ~3      !1
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPZ                                                     ~4, ->9
   18     5    >   NEW                                              $5      'InvalidArgumentException'
   19     6        SEND_VAL_EX                                              'steps+has+to+be+an+%28int%29'
          7        DO_FCALL                                      0          
          8      > THROW                                         0          $5
   22     9    >   IS_IDENTICAL                                             !1, 0
         10      > JMPZ                                                     ~7, ->12
   23    11    > > RETURN                                                   !0
   26    12    >   COUNT                                            ~8      !0
         13        ASSIGN                                                   !2, ~8
   28    14        IS_IDENTICAL                                             !2, 0
         15      > JMPZ                                                     ~10, ->17
   29    16    > > RETURN                                                   !0
   32    17    >   MOD                                              ~11     !1, !2
         18        ASSIGN                                                   !1, ~11
   33    19        ASSIGN_OP                                     3          !1, -1
   35    20        INIT_FCALL                                               'array_merge'
         21        INIT_FCALL                                               'array_slice'
         22        SEND_VAR                                                 !0
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $14     
         25        SEND_VAR                                                 $14
   36    26        INIT_FCALL                                               'array_slice'
         27        SEND_VAR                                                 !0
         28        SEND_VAL                                                 0
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                         $15     
         31        SEND_VAR                                                 $15
         32        DO_ICALL                                         $16     
         33      > RETURN                                                   $16
   37    34*     > RETURN                                                   null

End of function array_shift_circular

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.61 ms | 1403 KiB | 28 Q