What are some common methods for implementing pagination in PHP?

When dealing with a large dataset in PHP, it's common to implement pagination to display a limited number of records per page. One common method is to use SQL queries with LIMIT and OFFSET clauses to fetch only a subset of data at a time. Another approach is to use PHP arrays and array_slice function to achieve pagination.

// Example using SQL query with LIMIT and OFFSET
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$limit = 10;
$offset = ($page - 1) * $limit;

$sql = "SELECT * FROM table_name LIMIT $limit OFFSET $offset";
// Execute the SQL query and display results

// Example using PHP arrays and array_slice
$data = array(/* array of data */);
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$limit = 10;
$offset = ($page - 1) * $limit;

$paginatedData = array_slice($data, $offset, $limit);
// Display paginated data