PHP Simple Pagination

<?php
/*
$perpage = $_GET['pp'];
$total = $_GET['total'];
$currentpage = $_GET['c'];
$p = simple_pagination($perpage, $total, $currentpage);

echo $_POST['limit'];
echo "<br />";
echo $_POST['pagination'];
*/
function simple_pagination($perpage$total$currentpage){
    
$perpage = (intval($perpage) > $perpage 10);
    
$total = ((intval($total) > && $total $perpage) ? $total 10);
    global 
$limit;

    if( 
$total $perpage ){
    
        
$nextsimbol '>>';
        
$prevsimbol '<<';
        
        
$limits = array();
        
$tempperpage $perpage;
        
        for(
$k 0$k $total$k+=$perpage){
        
         if( (
$k $perpage) > $total){
          
$tempperpage $total $k;
         }
         
         
$limits[] = $k.", $tempperpage";
        }
        
        
$allpages count($limits);
        
$pages range(1$allpages);
        
        
$currentpage $currentpage ? ($currentpage) : 1;
        
$currentpage in_array($currentpage$pages) ? $currentpage 1;
        
        
$startpage 1;
        
$endpage $allpages;
        
$nextpage =  (($currentpage +1) <= $endpage ? ($currentpage 1) : $endpage);
        
$prevpage =  (($currentpage -1) >= $startpage ? ($currentpage 1) : $startpage);
        
        
$paginations[]= '<a class="pagination" title="Start" href="?page='.$startpage.'">startpage</a>&nbsp;&nbsp;';
        
$paginations[]= '<a class="pagination" title="Prev" href="?page='.($prevpage).'">prev</a>&nbsp;&nbsp;';
        for(
$i 1$i <= $allpages$i++){
            if(
$i == ($currentpage)){
                
$paginations[]= '<a class="pagination active" title="Page '.$i.'" href="?page='.$i.'">['.$i.']</a>&nbsp;&nbsp;';
            }else{                                    
                
$paginations[]= '<a class="pagination" title="Page '.$i.'" href="?page='.$i.'">'.$i.'</a>&nbsp;&nbsp;';
            }
        }
        
$paginations[]= '<a class="pagination" title="Next" href="?page='.$nextpage.'">next</a>&nbsp;&nbsp;';
        
$paginations[]= '<a class="pagination" title="End" href="?page='.$endpage.'">endpage</a>';
        
        
$_POST['pagination'] = implode("    \n"$paginations);
        
$_POST['limit'] = $limits[$currentpage-1];
    }else{
        
//if $total <= $perpage; set $limit = 10;
        
$_POST['limit'] = $perpage;
    }
}

?>