PHP Pagination - detect current page
<p>What is the best way to detect/print the current page number (pagination)? </p>

<p>I tried two different ways, and now i want to know if there exists a better way to do it.</p>

<p><strong>I:</strong></p>

<pre><code>$number = 12; //current page number
$all = 40; // all pages
$range = 4; // number of pages shown (up and down)
$min = $number-$range;
$max= $number+$range+1;

for($i=$min; $i&lt;$number;$i++) {
    echo "&lt;a href='#'&gt;$i&lt;/a&gt;&lt;br/&gt;";
}

echo "$number&lt;br/&gt;";

for($i=($number+1); $i&lt;$max;$i++) {
    echo "&lt;a href='#'&gt;$i&lt;/a&gt;&lt;/br&gt;";
}
</code></pre>

<p><strong>II:</strong></p>

<pre><code>$number = 12; //current page number
$all = 40; // all pages
$range = 4; // number of pages shown (up and down)
$min = $number-$range;
$max= $number+$range+1;

for($i=$min; $i&lt;$max;$i++) {
    if($i!=$number) {
        echo "&lt;a href='#'&gt;$i&lt;/a&gt;&lt;br/&gt;";
    } else {
        echo "$i&lt;br/&gt;"; 
    }
}
</code></pre>

<p>I also checked the speed of both solutions (using different high-number <code>$all</code> values) and first one is faster in most cases.</p>

<p>Thanks for suggestions :)</p>
