How to format numbers from 0 to 000 in php? : <p>I need to change the format of the integer. I know that needs to apply <code>sprintf</code> function but not sure how to apply properly.</p>

<p>The format turn 0 to 000. </p>

<p><strong>E.g turn 1 to 001 &amp; 19 to 019.</strong></p>

<p>i get item code from URL.</p>

<pre><code>$catCode=isset($_GET["cat"]) ? $_GET["cat"] : "ac";
$itemCode=isset($_GET["itemCode"]) ? $_GET["itemCode"] : "001";

foreach ($productArr[$catCode] as $imgNumber =&gt; $productDetail) {
            array_push($arr, $imgNumber);
            $imgNumber = $arr;
        }

//count the total number of items in the array
        $totalItem = count($arr);
        $prevItem = ($itemCode + $totalItem - 2) % $totalItem + 1;
        $nextItem = $itemCode % $totalItem + 1;

        if ($itemCode &gt; $totalItem || $itemCode &lt; 1) {
            $itemCode = 1;
        }

echo"&lt;a href='http://localhost/collectionDetail.php?cat={$catCode}&amp;itemCode={$prevItem}' &gt;&lt;img src='images/arrow_left.jpg'&gt; &lt;/a&gt;";
echo"&lt;a href='http://localhost/collectionDetail.php?cat={$catCode}&amp;itemCode={$nextItem}' &gt;&lt;img src='images/arrow_right.jpg'&gt; &lt;/a&gt;";
</code></pre>
