Say I wanted to start with the following number 001 and increment it by 1.. so 002, 003, 010, 011, 100, 101, and so on...
How would I do this??
Thank you!!
Increment with leading zeros
Moderator: General Moderators
- Gente
- Forum Contributor
- Posts: 252
- Joined: Wed Jun 13, 2007 9:43 am
- Location: Ukraine, Kharkov
- Contact:
Code: Select all
<?php
function format_number($i)
{
return substr('000'+$i, -3);
}
$i = 35;
echo format_number($i);
?>Cool thanks.. I also just found that this works too
Code: Select all
$i = 1
$n = sprintf("%03d",$i);