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

End of function pagination

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.87 ms | 1410 KiB | 19 Q