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) { 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/7GEHp
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                                                 
   25     3        INIT_FCALL                                               'header'
          4        SEND_VAL                                                 'content-type%3A+text%2Fplain'
          5        DO_ICALL                                                 
   27     6        ASSIGN                                                   !0, <array>
   29     7        COUNT                                            ~6      !0
          8        ASSIGN                                                   !1, ~6
   31     9        ASSIGN                                                   !2, 0
         10      > JMP                                                      ->25
   32    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                                                 
   31    24        PRE_INC                                                  !2
         25    >   IS_SMALLER                                               !2, !1
         26      > JMPNZ                                                    ~13, ->11
   34    27    > > RETURN                                                   1

Function array_circular:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7GEHp
function name:  array_circular
number of ops:  17
compiled vars:  !0 = $array, !1 = $steps
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1
   19     2        INIT_FCALL                                               'array_merge'
          3        INIT_FCALL                                               'array_slice'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $2      
          7        SEND_VAR                                                 $2
   20     8        INIT_FCALL                                               'array_slice'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 0
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $3      
         13        SEND_VAR                                                 $3
         14        DO_ICALL                                         $4      
         15      > RETURN                                                   $4
   21    16*     > RETURN                                                   null

End of function array_circular

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.55 ms | 1392 KiB | 25 Q