3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = 7 ; // try with 1, 7, 24, 75... $pagination_count = 40 ; // Number of results $maxrecords = 10 ; $num_pages = ceil($pagination_count / $maxrecords) ; // echo "num_pages=$num_pages\n" ; // Just for dev if ($start > $num_pages) { $start = $num_pages; } if ($num_pages < 6) { for ($i = 0; $i < $num_pages ; $i++) { echo render_page_link($i, $start); } } else { // Begining for ($i = 0 ; $i < min(3, $num_pages); $i++) { echo render_page_link($i,$start) ; } echo ' (...) ' ; $have_middle = ($start > 3 && $start <= $num_pages - 3) ; if ($have_middle) { // Around current for ($i = max(3, $start - 3); $i < min($start + 3 - 1, $num_pages - 3) ; $i++) { echo render_page_link($i,$start) ; } } // Ending if ($have_middle) echo ' (...) ' ; for ($i = $num_pages - 3; $i < $num_pages ; $i++) { echo render_page_link($i,$start); } } echo "\n"; // just because I test on CLI. // Here is a little function to display the link: // Currently just "plain text", but could be <a> or <span> with CSS... function render_page_link($index, $current = -1) { if ($index != $current - 1) return ($index+1) . " " ; return "[".($index+1)."] " ; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 24
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 15
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 15
Branch analysis from position: 23
Branch analysis from position: 15
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 26
Branch analysis from position: 38
2 jumps found. (Code = 46) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 68
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 53
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 70
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 73
Branch analysis from position: 81
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 73
Branch analysis from position: 81
Branch analysis from position: 73
Branch analysis from position: 70
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 53
Branch analysis from position: 68
Branch analysis from position: 53
Branch analysis from position: 68
Branch analysis from position: 44
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 26
Branch analysis from position: 38
Branch analysis from position: 26
Branch analysis from position: 11
filename:       /in/TXAMR
function name:  (null)
number of ops:  83
compiled vars:  !0 = $start, !1 = $pagination_count, !2 = $maxrecords, !3 = $num_pages, !4 = $i, !5 = $have_middle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 7
    5     1        ASSIGN                                                   !1, 40
    6     2        ASSIGN                                                   !2, 10
    8     3        INIT_FCALL                                               'ceil'
          4        DIV                                              ~9      !1, !2
          5        SEND_VAL                                                 ~9
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !3, $10
   11     8        IS_SMALLER                                               !3, !0
          9      > JMPZ                                                     ~12, ->11
         10    >   ASSIGN                                                   !0, !3
   13    11    >   IS_SMALLER                                               !3, 6
         12      > JMPZ                                                     ~14, ->24
   14    13    >   ASSIGN                                                   !4, 0
         14      > JMP                                                      ->21
   15    15    >   INIT_FCALL_BY_NAME                                       'render_page_link'
         16        SEND_VAR_EX                                              !4
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0  $16     
         19        ECHO                                                     $16
   14    20        PRE_INC                                                  !4
         21    >   IS_SMALLER                                               !4, !3
         22      > JMPNZ                                                    ~18, ->15
   13    23    > > JMP                                                      ->81
   21    24    >   ASSIGN                                                   !4, 0
         25      > JMP                                                      ->32
   22    26    >   INIT_FCALL_BY_NAME                                       'render_page_link'
         27        SEND_VAR_EX                                              !4
         28        SEND_VAR_EX                                              !0
         29        DO_FCALL                                      0  $20     
         30        ECHO                                                     $20
   21    31        PRE_INC                                                  !4
         32    >   INIT_FCALL                                               'min'
         33        SEND_VAL                                                 3
         34        SEND_VAR                                                 !3
         35        DO_ICALL                                         $22     
         36        IS_SMALLER                                               !4, $22
         37      > JMPNZ                                                    ~23, ->26
   24    38    >   ECHO                                                     '+%28...%29+'
   26    39        IS_SMALLER                                       ~24     3, !0
         40      > JMPZ_EX                                          ~24     ~24, ->44
         41    >   SUB                                              ~25     !3, 3
         42        IS_SMALLER_OR_EQUAL                              ~26     !0, ~25
         43        BOOL                                             ~24     ~26
         44    >   ASSIGN                                                   !5, ~24
   27    45      > JMPZ                                                     !5, ->68
   29    46    >   INIT_FCALL                                               'max'
         47        SEND_VAL                                                 3
         48        SUB                                              ~28     !0, 3
         49        SEND_VAL                                                 ~28
         50        DO_ICALL                                         $29     
         51        ASSIGN                                                   !4, $29
         52      > JMP                                                      ->59
   30    53    >   INIT_FCALL_BY_NAME                                       'render_page_link'
         54        SEND_VAR_EX                                              !4
         55        SEND_VAR_EX                                              !0
         56        DO_FCALL                                      0  $31     
         57        ECHO                                                     $31
   29    58        PRE_INC                                                  !4
         59    >   INIT_FCALL                                               'min'
         60        ADD                                              ~33     !0, 3
         61        SUB                                              ~34     ~33, 1
         62        SEND_VAL                                                 ~34
         63        SUB                                              ~35     !3, 3
         64        SEND_VAL                                                 ~35
         65        DO_ICALL                                         $36     
         66        IS_SMALLER                                               !4, $36
         67      > JMPNZ                                                    ~37, ->53
   35    68    > > JMPZ                                                     !5, ->70
         69    >   ECHO                                                     '+%28...%29+'
   36    70    >   SUB                                              ~38     !3, 3
         71        ASSIGN                                                   !4, ~38
         72      > JMP                                                      ->79
   37    73    >   INIT_FCALL_BY_NAME                                       'render_page_link'
         74        SEND_VAR_EX                                              !4
         75        SEND_VAR_EX                                              !0
         76        DO_FCALL                                      0  $40     
         77        ECHO                                                     $40
   36    78        PRE_INC                                                  !4
         79    >   IS_SMALLER                                               !4, !3
         80      > JMPNZ                                                    ~42, ->73
   42    81    >   ECHO                                                     '%0A'
   50    82      > RETURN                                                   1

Function render_page_link:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TXAMR
function name:  render_page_link
number of ops:  13
compiled vars:  !0 = $index, !1 = $current
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      -1
   48     2        SUB                                              ~2      !1, 1
          3        IS_NOT_EQUAL                                             !0, ~2
          4      > JMPZ                                                     ~3, ->8
          5    >   ADD                                              ~4      !0, 1
          6        CONCAT                                           ~5      ~4, '+'
          7      > RETURN                                                   ~5
   49     8    >   ADD                                              ~6      !0, 1
          9        CONCAT                                           ~7      '%5B', ~6
         10        CONCAT                                           ~8      ~7, '%5D+'
         11      > RETURN                                                   ~8
   50    12*     > RETURN                                                   null

End of function render_page_link

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.28 ms | 1016 KiB | 16 Q