3v4l.org

run code in 300+ PHP versions simultaneously
<?php function pagination($url, $actualPage, $numberOfElements, $numberOfElementsPerPage = 10) { $numberOfPageAroundActualPage = 2; $numberOfPageAroundEdges = 1; $url = (string)$url; $actualPage = (int)$actualPage; $numberOfElements = (int)$numberOfElements; $numberOfElementsPerPage = (int)$numberOfElementsPerPage; $numberOfPages = (int)ceil($numberOfElements / $numberOfElementsPerPage); $shownPages = array(); if (($actualPage - 1) > ($numberOfPageAroundActualPage + $numberOfPageAroundEdges + 1)) { for ($i = 1; $i < ($numberOfPageAroundEdges + 1); ++$i) $shownPages[] = $i; $shownPages[] = 'separator'; for ($i = ($actualPage - $numberOfPageAroundActualPage); $i < $actualPage; ++$i) $shownPages[] = $i; } else { for ($i = 1; $i < $actualPage; ++$i) $shownPages[] = $i; } $shownPages[] = $actualPage; if (($numberOfPages - $actualPage) > ($numberOfPageAroundActualPage + $numberOfPageAroundEdges + 1)) { for ($i = ($actualPage + 1); $i <= ($actualPage + $numberOfPageAroundActualPage); ++$i) $shownPages[] = $i; $shownPages[] = 'separator'; for ($i = ($numberOfPages - $numberOfPageAroundEdges + 1); $i <= $numberOfPages; ++$i) $shownPages[] = $i; } else { for ($i = ($actualPage + 1); $i <= $numberOfPages; ++$i) $shownPages[] = $i; } $html = '<div class="pagination" role="navigation">'; $html .= '<div class="pagination-short">'; if (1 === $actualPage) $html .= '<span><i class="fa fa-angle-double-left"></i></span> '; else $html .= '<a href="'.$url.($actualPage-1).'" title="Aller à la page précédente"><i class="fa fa-angle-double-left"></i></a> '; if ($numberOfPages === $actualPage) $html .= '<span><i class="fa fa-angle-double-right"></i></span> '; else $html .= '<a href="'.$url.($actualPage+1).'" title="Aller à la page suivante"><i class="fa fa-angle-double-right"></i></a> '; $html .= '</div>'; $html .= '<div class="pagination-pages">'; foreach ($shownPages AS $page) { if ('separator' === $page) $html .= '<span>…</span> '; elseif ($actualPage === $page) $html .= '<span>'.$page.'</span> '; else $html .= '<a href="'.$url.$page.'" title="Aller à la page '.$page.'">'.$page.'</a> '; } $html .= '</div>'; $html .= '<div class="pagination-details">'; $html .= 'Page '.$actualPage.' sur '.$numberOfPages.'. '; $html .= 'Éléments '.(($actualPage - 1) * $numberOfElementsPerPage).' à '.($actualPage * $numberOfElementsPerPage).' sur '.$numberOfElements.' affichés.'; $html .= '</div>'; $html .= '</div>'; return $html; } echo pagination('index.php?p=2&page=', 1, 8, 10); echo pagination('index.php?p=2&page=', 14, 315, 10); echo pagination('index.php?p=2&page=', 5, 97, 10); echo pagination('index.php?p=2&page=', 5, 88, 10);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ggfnr
function name:  (null)
number of ops:  29
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   INIT_FCALL                                               'pagination'
          1        SEND_VAL                                                 'index.php%3Fp%3D2%26page%3D'
          2        SEND_VAL                                                 1
          3        SEND_VAL                                                 8
          4        SEND_VAL                                                 10
          5        DO_FCALL                                      0  $0      
          6        ECHO                                                     $0
   81     7        INIT_FCALL                                               'pagination'
          8        SEND_VAL                                                 'index.php%3Fp%3D2%26page%3D'
          9        SEND_VAL                                                 14
         10        SEND_VAL                                                 315
         11        SEND_VAL                                                 10
         12        DO_FCALL                                      0  $1      
         13        ECHO                                                     $1
   82    14        INIT_FCALL                                               'pagination'
         15        SEND_VAL                                                 'index.php%3Fp%3D2%26page%3D'
         16        SEND_VAL                                                 5
         17        SEND_VAL                                                 97
         18        SEND_VAL                                                 10
         19        DO_FCALL                                      0  $2      
         20        ECHO                                                     $2
   83    21        INIT_FCALL                                               'pagination'
         22        SEND_VAL                                                 'index.php%3Fp%3D2%26page%3D'
         23        SEND_VAL                                                 5
         24        SEND_VAL                                                 88
         25        SEND_VAL                                                 10
         26        DO_FCALL                                      0  $3      
         27        ECHO                                                     $3
         28      > RETURN                                                   1

Function pagination:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 45
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 28
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 39
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 80
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 62
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 74
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 94
Branch analysis from position: 92
1 jumps found. (Code = 42) Position 1 = 99
Branch analysis from position: 99
2 jumps found. (Code = 43) Position 1 = 101, Position 2 = 103
Branch analysis from position: 101
1 jumps found. (Code = 42) Position 1 = 108
Branch analysis from position: 108
2 jumps found. (Code = 77) Position 1 = 111, Position 2 = 131
Branch analysis from position: 111
2 jumps found. (Code = 78) Position 1 = 112, Position 2 = 131
Branch analysis from position: 112
2 jumps found. (Code = 43) Position 1 = 114, Position 2 = 116
Branch analysis from position: 114
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
Branch analysis from position: 116
2 jumps found. (Code = 43) Position 1 = 118, Position 2 = 122
Branch analysis from position: 118
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 122
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
Branch analysis from position: 131
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 131
Branch analysis from position: 103
2 jumps found. (Code = 77) Position 1 = 111, Position 2 = 131
Branch analysis from position: 111
Branch analysis from position: 131
Branch analysis from position: 94
2 jumps found. (Code = 43) Position 1 = 101, Position 2 = 103
Branch analysis from position: 101
Branch analysis from position: 103
Branch analysis from position: 74
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 74
Branch analysis from position: 79
Branch analysis from position: 74
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 62
Branch analysis from position: 68
Branch analysis from position: 62
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 83
Branch analysis from position: 88
Branch analysis from position: 83
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 83
Branch analysis from position: 88
Branch analysis from position: 83
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 39
Branch analysis from position: 44
Branch analysis from position: 39
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 28
Branch analysis from position: 34
Branch analysis from position: 28
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 47
Branch analysis from position: 52
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 47
Branch analysis from position: 52
Branch analysis from position: 47
filename:       /in/Ggfnr
function name:  pagination
number of ops:  153
compiled vars:  !0 = $url, !1 = $actualPage, !2 = $numberOfElements, !3 = $numberOfElementsPerPage, !4 = $numberOfPageAroundActualPage, !5 = $numberOfPageAroundEdges, !6 = $numberOfPages, !7 = $shownPages, !8 = $i, !9 = $html, !10 = $page
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      10
    4     4        ASSIGN                                                   !4, 2
    5     5        ASSIGN                                                   !5, 1
    7     6        CAST                                          6  ~13     !0
          7        ASSIGN                                                   !0, ~13
    8     8        CAST                                          4  ~15     !1
          9        ASSIGN                                                   !1, ~15
    9    10        CAST                                          4  ~17     !2
         11        ASSIGN                                                   !2, ~17
   10    12        CAST                                          4  ~19     !3
         13        ASSIGN                                                   !3, ~19
   11    14        INIT_FCALL                                               'ceil'
         15        DIV                                              ~21     !2, !3
         16        SEND_VAL                                                 ~21
         17        DO_ICALL                                         $22     
         18        CAST                                          4  ~23     $22
         19        ASSIGN                                                   !6, ~23
   13    20        ASSIGN                                                   !7, <array>
   15    21        SUB                                              ~26     !1, 1
         22        ADD                                              ~27     !4, !5
         23        ADD                                              ~28     ~27, 1
         24        IS_SMALLER                                               ~28, ~26
         25      > JMPZ                                                     ~29, ->45
   16    26    >   ASSIGN                                                   !8, 1
         27      > JMP                                                      ->31
   17    28    >   ASSIGN_DIM                                               !7
         29        OP_DATA                                                  !8
   16    30        PRE_INC                                                  !8
         31    >   ADD                                              ~33     !5, 1
         32        IS_SMALLER                                               !8, ~33
         33      > JMPNZ                                                    ~34, ->28
   19    34    >   ASSIGN_DIM                                               !7
         35        OP_DATA                                                  'separator'
   21    36        SUB                                              ~36     !1, !4
         37        ASSIGN                                                   !8, ~36
         38      > JMP                                                      ->42
   22    39    >   ASSIGN_DIM                                               !7
         40        OP_DATA                                                  !8
   21    41        PRE_INC                                                  !8
         42    >   IS_SMALLER                                               !8, !1
         43      > JMPNZ                                                    ~40, ->39
         44    > > JMP                                                      ->52
   25    45    >   ASSIGN                                                   !8, 1
         46      > JMP                                                      ->50
   26    47    >   ASSIGN_DIM                                               !7
         48        OP_DATA                                                  !8
   25    49        PRE_INC                                                  !8
         50    >   IS_SMALLER                                               !8, !1
         51      > JMPNZ                                                    ~44, ->47
   29    52    >   ASSIGN_DIM                                               !7
         53        OP_DATA                                                  !1
   31    54        SUB                                              ~46     !6, !1
         55        ADD                                              ~47     !4, !5
         56        ADD                                              ~48     ~47, 1
         57        IS_SMALLER                                               ~48, ~46
         58      > JMPZ                                                     ~49, ->80
   32    59    >   ADD                                              ~50     !1, 1
         60        ASSIGN                                                   !8, ~50
         61      > JMP                                                      ->65
   33    62    >   ASSIGN_DIM                                               !7
         63        OP_DATA                                                  !8
   32    64        PRE_INC                                                  !8
         65    >   ADD                                              ~54     !1, !4
         66        IS_SMALLER_OR_EQUAL                                      !8, ~54
         67      > JMPNZ                                                    ~55, ->62
   35    68    >   ASSIGN_DIM                                               !7
         69        OP_DATA                                                  'separator'
   37    70        SUB                                              ~57     !6, !5
         71        ADD                                              ~58     ~57, 1
         72        ASSIGN                                                   !8, ~58
         73      > JMP                                                      ->77
   38    74    >   ASSIGN_DIM                                               !7
         75        OP_DATA                                                  !8
   37    76        PRE_INC                                                  !8
         77    >   IS_SMALLER_OR_EQUAL                                      !8, !6
         78      > JMPNZ                                                    ~62, ->74
         79    > > JMP                                                      ->88
   41    80    >   ADD                                              ~63     !1, 1
         81        ASSIGN                                                   !8, ~63
         82      > JMP                                                      ->86
   42    83    >   ASSIGN_DIM                                               !7
         84        OP_DATA                                                  !8
   41    85        PRE_INC                                                  !8
         86    >   IS_SMALLER_OR_EQUAL                                      !8, !6
         87      > JMPNZ                                                    ~67, ->83
   46    88    >   ASSIGN                                                   !9, '%3Cdiv+class%3D%22pagination%22+role%3D%22navigation%22%3E'
   47    89        ASSIGN_OP                                     8          !9, '%3Cdiv+class%3D%22pagination-short%22%3E'
   49    90        IS_IDENTICAL                                             !1, 1
         91      > JMPZ                                                     ~70, ->94
   50    92    >   ASSIGN_OP                                     8          !9, '%3Cspan%3E%3Ci+class%3D%22fa+fa-angle-double-left%22%3E%3C%2Fi%3E%3C%2Fspan%3E+'
         93      > JMP                                                      ->99
   52    94    >   CONCAT                                           ~72     '%3Ca+href%3D%22', !0
         95        SUB                                              ~73     !1, 1
         96        CONCAT                                           ~74     ~72, ~73
         97        CONCAT                                           ~75     ~74, '%22+title%3D%22Aller+%C3%A0+la+page+pr%C3%A9c%C3%A9dente%22%3E%3Ci+class%3D%22fa+fa-angle-double-left%22%3E%3C%2Fi%3E%3C%2Fa%3E+'
         98        ASSIGN_OP                                     8          !9, ~75
   54    99    >   IS_IDENTICAL                                             !6, !1
        100      > JMPZ                                                     ~77, ->103
   55   101    >   ASSIGN_OP                                     8          !9, '%3Cspan%3E%3Ci+class%3D%22fa+fa-angle-double-right%22%3E%3C%2Fi%3E%3C%2Fspan%3E+'
        102      > JMP                                                      ->108
   57   103    >   CONCAT                                           ~79     '%3Ca+href%3D%22', !0
        104        ADD                                              ~80     !1, 1
        105        CONCAT                                           ~81     ~79, ~80
        106        CONCAT                                           ~82     ~81, '%22+title%3D%22Aller+%C3%A0+la+page+suivante%22%3E%3Ci+class%3D%22fa+fa-angle-double-right%22%3E%3C%2Fi%3E%3C%2Fa%3E+'
        107        ASSIGN_OP                                     8          !9, ~82
   59   108    >   ASSIGN_OP                                     8          !9, '%3C%2Fdiv%3E'
   60   109        ASSIGN_OP                                     8          !9, '%3Cdiv+class%3D%22pagination-pages%22%3E'
   61   110      > FE_RESET_R                                       $86     !7, ->131
        111    > > FE_FETCH_R                                               $86, !10, ->131
   62   112    >   IS_IDENTICAL                                             !10, 'separator'
        113      > JMPZ                                                     ~87, ->116
   63   114    >   ASSIGN_OP                                     8          !9, '%3Cspan%3E%E2%80%A6%3C%2Fspan%3E+'
        115      > JMP                                                      ->130
   64   116    >   IS_IDENTICAL                                             !1, !10
        117      > JMPZ                                                     ~89, ->122
   65   118    >   CONCAT                                           ~90     '%3Cspan%3E', !10
        119        CONCAT                                           ~91     ~90, '%3C%2Fspan%3E+'
        120        ASSIGN_OP                                     8          !9, ~91
        121      > JMP                                                      ->130
   67   122    >   CONCAT                                           ~93     '%3Ca+href%3D%22', !0
        123        CONCAT                                           ~94     ~93, !10
        124        CONCAT                                           ~95     ~94, '%22+title%3D%22Aller+%C3%A0+la+page+'
        125        CONCAT                                           ~96     ~95, !10
        126        CONCAT                                           ~97     ~96, '%22%3E'
        127        CONCAT                                           ~98     ~97, !10
        128        CONCAT                                           ~99     ~98, '%3C%2Fa%3E+'
        129        ASSIGN_OP                                     8          !9, ~99
   61   130    > > JMP                                                      ->111
        131    >   FE_FREE                                                  $86
   69   132        ASSIGN_OP                                     8          !9, '%3C%2Fdiv%3E'
   70   133        ASSIGN_OP                                     8          !9, '%3Cdiv+class%3D%22pagination-details%22%3E'
   71   134        CONCAT                                           ~103    'Page+', !1
        135        CONCAT                                           ~104    ~103, '+sur+'
        136        CONCAT                                           ~105    ~104, !6
        137        CONCAT                                           ~106    ~105, '.+'
        138        ASSIGN_OP                                     8          !9, ~106
   72   139        SUB                                              ~108    !1, 1
        140        MUL                                              ~109    !3, ~108
        141        CONCAT                                           ~110    '%C3%89l%C3%A9ments+', ~109
        142        CONCAT                                           ~111    ~110, '+%C3%A0+'
        143        MUL                                              ~112    !1, !3
        144        CONCAT                                           ~113    ~111, ~112
        145        CONCAT                                           ~114    ~113, '+sur+'
        146        CONCAT                                           ~115    ~114, !2
        147        CONCAT                                           ~116    ~115, '+affich%C3%A9s.'
        148        ASSIGN_OP                                     8          !9, ~116
   73   149        ASSIGN_OP                                     8          !9, '%3C%2Fdiv%3E'
   74   150        ASSIGN_OP                                     8          !9, '%3C%2Fdiv%3E'
   76   151      > RETURN                                                   !9
   77   152*     > RETURN                                                   null

End of function pagination

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.81 ms | 1419 KiB | 19 Q