What are some strategies for paginating content in PHP to improve page loading times?

When dealing with large amounts of content, paginating it can significantly improve page loading times by only displaying a portion of the content at a time. This can prevent the need to load and render all content at once, reducing the strain on server resources and improving the overall user experience.

// Assuming $content is an array of content to be paginated
$itemsPerPage = 10;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$totalItems = count($content);
$totalPages = ceil($totalItems / $itemsPerPage);
$offset = ($page - 1) * $itemsPerPage;

$paginatedContent = array_slice($content, $offset, $itemsPerPage);

// Display paginated content
foreach ($paginatedContent as $item) {
    echo $item . "<br>";
}

// Display pagination links
for ($i = 1; $i <= $totalPages; $i++) {
    echo "<a href='?page=$i'>$i</a> ";
}