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)."] " ; }
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
1 2 3 [4]
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
140.69 ms | 407 KiB | 5 Q