for ($number = 1; $number <= 16; $number++) {
echo $number . "\n";
}
This code outputs:
1
2
3
...
16
How can I get PHP to output the numbers preceded by zeros?
01
02
03
...
16
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use
sprintfto format your number to a string, orprintfto format it and display the string immediatly.You’d have to specify a format such as this one, I’d say :
%02d:02d(Even if you have what you want here, you should read the manual page of
sprintf: there are a lot of possibilities, depending on the kind of data you are using, and the kind of output formating you want)And, as a demo, if
temp.phpcontains this portion of code :Calling it will give you :