PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
lazersam
Forum Contributor
Posts: 105 Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK
Post
by lazersam » Sat Jun 04, 2005 10:31 am
Anyone know how to turn one digit numbers like '1' into three digit numbers like '001' using a function? So, for example 81 would become 081.
Larry.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sat Jun 04, 2005 10:40 am
Look in the manual for the functions number_format, sprintf, etc...
AGISB
Forum Contributor
Posts: 422 Joined: Fri Jul 09, 2004 1:23 am
Post
by AGISB » Sat Jun 04, 2005 1:10 pm
its basically as simple as
Code: Select all
if ($var <= 9 && $var >= 0) {
$var = "0".$var;
} elseif ($var <= 99) {
$var = "00".$var;
}
Revan
Forum Commoner
Posts: 83 Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:
Post
by Revan » Sat Jun 04, 2005 1:20 pm
Revan
Forum Commoner
Posts: 83 Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:
Post
by Revan » Sat Jun 04, 2005 3:44 pm
Ambush Commander wrote: Hmm.. has anyone ever checked which is faster?
printf, also less redundant code with printf.