PHP code example of jdzm / jdz-paginator

1. Go to this page and download the library: Download jdzm/jdz-paginator 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/ */

    

jdzm / jdz-paginator example snippets




$products = array(
	array('id' => 1,'nombre' => 'Producto 1','precio' => 100,'created_at' => date('Y-m-d')),
	array('id' => 2,'nombre' => 'Producto 2','precio' => 200,'created_at' => date('Y-m-d')),
	array('id' => 3,'nombre' => 'Producto 3','precio' => 250,'created_at' => date('Y-m-d')),
	array('id' => 5,'nombre' => 'Producto 4','precio' => 350, 'created_at' => date('Y-m-d')),
	array('id' => 6,'nombre' => 'Producto 5','precio' => 50, 'created_at' => date('Y-m-d'))
);

$pageNumber = 0;  // Page number for current page
	
$size = 2;   // Elements by page

$offset = $pageNumber * $size;  // get offset

$countArray = sizeof($productos);

$products = array_slice($products, $offset, $size);

use Jdzm\JDZPaginator\Pagination\Paginator;
$paginator = new Paginator($pageNumber, $size, $countArray, $products);

header('Content-Type: application/json');
	
echo json_encode($paginator->paginate());   // GET DATA IN JSON FORMAT