Solved

2 digits

Posted on 2009-05-06
2
206 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating Functions in phpMyAdmin 8 26
Redirect 301 from one address  to another 5 27
Wordpress Query 5 27
Use Select Query to Return Results as a Form 9 25
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

821 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