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_circular(array $array, $steps = 1) { 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 = array("1" => "Primeiro", "2"=>"Segundo", "3"=>"Terceiro", "4"=> "Quarto"); $l = sizeof($a); for ($i = 0 ; $i < $l; $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 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 11
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 11
Branch analysis from position: 27
Branch analysis from position: 11
filename:       /in/OKBXX
function name:  (null)
number of ops:  28
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                                                 
   37     3        INIT_FCALL                                               'header'
          4        SEND_VAL                                                 'content-type%3A+text%2Fplain'
          5        DO_ICALL                                                 
   39     6        ASSIGN                                                   !0, <array>
   41     7        COUNT                                            ~6      !0
          8        ASSIGN                                                   !1, ~6
   43     9        ASSIGN                                                   !2, 0
         10      > JMP                                                      ->25
   44    11    >   INIT_FCALL                                               'printf'
         12        SEND_VAL                                                 '%25+3s++%3A++%25s%0A'
         13        SEND_VAR                                                 !2
         14        INIT_FCALL                                               'implode'
         15        SEND_VAL                                                 '%2C+'
         16        INIT_FCALL_BY_NAME                                       'array_shift_circular'
         17        SEND_VAR_EX                                              !0
         18        SEND_VAR_EX                                              !2
         19        DO_FCALL                                      0  $9      
         20        SEND_VAR                                                 $9
         21        DO_ICALL                                         $10     
         22        SEND_VAR                                                 $10
         23        DO_ICALL                                                 
   43    24        PRE_INC                                                  !2
         25    >   IS_SMALLER                                               !2, !1
         26      > JMPNZ                                                    ~13, ->11
   46    27    > > RETURN                                                   1

Function array_circular:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKBXX
function name:  array_circular
number of ops:  28
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
   18     2        IS_IDENTICAL                                             !1, 0
          3      > JMPZ                                                     ~3, ->5
   19     4    > > RETURN                                                   !0
   22     5    >   COUNT                                            ~4      !0
          6        ASSIGN                                                   !2, ~4
   24     7        IS_IDENTICAL                                             !2, 0
          8      > JMPZ                                                     ~6, ->10
   25     9    > > RETURN                                                   !0
   28    10    >   MOD                                              ~7      !1, !2
         11        ASSIGN                                                   !1, ~7
   29    12        ASSIGN_OP                                     3          !1, -1
   31    13        INIT_FCALL                                               'array_merge'
         14        INIT_FCALL                                               'array_slice'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $10     
         18        SEND_VAR                                                 $10
   32    19        INIT_FCALL                                               'array_slice'
         20        SEND_VAR                                                 !0
         21        SEND_VAL                                                 0
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $11     
         24        SEND_VAR                                                 $11
         25        DO_ICALL                                         $12     
         26      > RETURN                                                   $12
   33    27*     > RETURN                                                   null

End of function array_circular

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.31 ms | 1405 KiB | 25 Q