foreach pagination

Here is the code I used to solve my problem:

<?php
$url = $_SERVER["REQUEST_URI"];
$segments = explode("https://wordpress.stackexchange.com/", $url);
$page = is_numeric($segments[count($segments)-2]) ? $segments[count($segments)-2] : 1;
$next = $page + 1;
$prev = $page - 1;
$issues_per_page = 11;
$lastpage = ceil(wp_count_terms( 'mag') / $issues_per_page) ;
?>

<?php wp_count_terms( 'mag' ); ?>

<table>
<tr>
<?php $col = 0; ?>
<?php foreach (get_terms('mag', array('offset' => ($page - 1) * $issues_per_page, 'number' => $issues_per_page)) as $cat) : ?>

<?php if ($col > 0 && $col % 3 == 0): ?>
</tr>
<tr>
<?php endif; ?>
<?php $col++; ?>

<td>

<a href="https://wordpress.stackexchange.com/questions/123685/<?php echo get_term_link($cat->slug,"mag'); ?>"><strong><?php echo $cat->name; ?></strong></a><br>

<em><a href="https://wordpress.stackexchange.com/questions/123685/<?php echo get_term_link($cat->slug,"mag'); ?>"><?php echo $cat->description; ?></a></em><br>

<a href="https://wordpress.stackexchange.com/questions/123685/<?php echo get_term_link($cat->slug,"mag'); ?>"><img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" /></a>
</td>
<?php endforeach; ?>
</tr>
</table>


<?php if ($prev > 0) : ?>
<a href="http://wordpress.stackexchange.com/mag-archive?page=<?php echo $prev; ?>">Previous</a>
<?php endif ?> 
<?php if ($page < $lastpage) : ?>
<a href="http://wordpress.stackexchange.com/mag-archive?page=<?php echo $next; ?>">Next</a>
<?php endif ?>