Solved

2 digits

Posted on 2009-05-06
2
205 Views
Last Modified: 2012-05-06
hello there,
i am doing a for($i) and displaying the data but its showing it like 1,2,3,4
is it possible to show it like this 01,02,03?
<? for($i=1;$i<=10;$i++) { ?>

Open in new window

0
Comment
Question by:XK8ER
2 Comments
 

Expert Comment

by:MunichJoe2009
ID: 24313873
This may solve your problem:

http://www.htmlite.com/php011.phphttp://www.htmlite.com/php011.php

(see middle of the page)

Regards,
MunichJoe2009

0
 
LVL 17

Accepted Solution

by:
Chris Harte earned 500 total points
ID: 24313887
Depends on how you are trying to display $i.
Using printf() instead of echo allows you to add a leading zero


for ($i = 1; $i <= 10; $i++)
{
     printf("%02d", $i);
}

Open in new window

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question