PHP code example of stopsopa / paginator-test

1. Go to this page and download the library: Download stopsopa/paginator-test library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stopsopa / paginator-test example snippets




use Stopsopa\PaginatorTest\Paginator;

', 1);

$paginator = new Paginator(
    3, // per page
    // function to return length of the set
    function () use ($list) {
        return count($list);
    },
    // function to provide one page of elements from set
    function ($offset, $limit) use ($list) {
        return array_slice($list, $offset, $limit);
    },
    3 // how many buttons around current
);

$page = $paginator->getPage(3);

var_dump($page->elements());
//array(3) {
//      [0] => string(1) "g"
//      [1] => string(1) "h"
//      [2] => string(1) "i"
//}

var_dump($page->pages());
//array(3) {
//    [0] => array(2) {
//        'page' => int(2)
//        'current' => bool(false)
//    }
//    [1] => array(2) {
//        'page' => int(3)
//        'current' => bool(true)
//    }
//    [2] => array(2) {
//        'page' => int(4)
//        'current' => bool(false)
//    }
//}