3v4l.org

run code in 300+ PHP versions simultaneously
#!/usr/bin/env php <?php /** * Generate the page order for building a PDF of A4 pages printed as an A5 Booklet form on a MacBook that is * missing the proper A5 Booklet form. * * @return int[] */ function getPageList(int $pageCount): array { // Generate a list of page numbers, including additional blank pages required to get the total number of page // divisible by 4 to represent the list of A4 pages to be printed in as an A5 Booklet form. $pages = $pageCount % 4 !== 0 ? array_merge( range(1, $pageCount), array_fill( $pageCount + 1, 4 - ($pageCount % 4), 'blank' ) ) : range(1, $pageCount); $results = []; // Extract the pages to be printed in the relevant order for an A5 Booklet form. while (count($pages) !== 0) { // The page order is last page, first page, first + 1, last - 1. // As we remove these pages from $pages, we can repeat this extraction whilst there are no pages to left. $results[1 + count($results)] = [ 'Left front' => array_pop($pages), 'Right front' => array_shift($pages), 'Right back' => array_shift($pages), 'Left back' => array_pop($pages), ]; } return $results; } print_r(getPageList($argv[1]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ov06C
function name:  (null)
number of ops:  8
compiled vars:  !0 = $argv
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'getpagelist'
          2        FETCH_DIM_R                                      ~1      !0, 1
          3        SEND_VAL                                                 ~1
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function getpagelist:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 30
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 30
Branch analysis from position: 53
Branch analysis from position: 30
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
filename:       /in/Ov06C
function name:  getPageList
number of ops:  57
compiled vars:  !0 = $pageCount, !1 = $pages, !2 = $results
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   14     1        MOD                                              ~3      !0, 4
          2        IS_NOT_IDENTICAL                                         ~3, 0
          3      > JMPZ                                                     ~4, ->22
   16     4    >   INIT_FCALL                                               'array_merge'
   17     5        INIT_FCALL                                               'range'
          6        SEND_VAL                                                 1
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
   18    10        INIT_FCALL                                               'array_fill'
   19    11        ADD                                              ~6      !0, 1
         12        SEND_VAL                                                 ~6
   20    13        MOD                                              ~7      !0, 4
         14        SUB                                              ~8      4, ~7
         15        SEND_VAL                                                 ~8
   21    16        SEND_VAL                                                 'blank'
         17        DO_ICALL                                         $9      
         18        SEND_VAR                                                 $9
         19        DO_ICALL                                         $10     
         20        QM_ASSIGN                                        ~11     $10
         21      > JMP                                                      ->27
   24    22    >   INIT_FCALL                                               'range'
         23        SEND_VAL                                                 1
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                         $12     
         26        QM_ASSIGN                                        ~11     $12
   14    27    >   ASSIGN                                                   !1, ~11
   26    28        ASSIGN                                                   !2, <array>
   29    29      > JMP                                                      ->50
   32    30    >   COUNT                                            ~15     !2
         31        ADD                                              ~16     1, ~15
   33    32        INIT_FCALL                                               'array_pop'
         33        SEND_REF                                                 !1
         34        DO_ICALL                                         $18     
         35        INIT_ARRAY                                       ~19     $18, 'Left+front'
   34    36        INIT_FCALL                                               'array_shift'
         37        SEND_REF                                                 !1
         38        DO_ICALL                                         $20     
         39        ADD_ARRAY_ELEMENT                                ~19     $20, 'Right+front'
   35    40        INIT_FCALL                                               'array_shift'
         41        SEND_REF                                                 !1
         42        DO_ICALL                                         $21     
         43        ADD_ARRAY_ELEMENT                                ~19     $21, 'Right+back'
   36    44        INIT_FCALL                                               'array_pop'
         45        SEND_REF                                                 !1
         46        DO_ICALL                                         $22     
         47        ADD_ARRAY_ELEMENT                                ~19     $22, 'Left+back'
   32    48        ASSIGN_DIM                                               !2, ~16
   36    49        OP_DATA                                                  ~19
   29    50    >   COUNT                                            ~23     !1
         51        IS_NOT_IDENTICAL                                         ~23, 0
         52      > JMPNZ                                                    ~24, ->30
   40    53    >   VERIFY_RETURN_TYPE                                       !2
         54      > RETURN                                                   !2
   41    55*       VERIFY_RETURN_TYPE                                       
         56*     > RETURN                                                   null

End of function getpagelist

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.84 ms | 950 KiB | 27 Q