?
Solved

Pre zero's in counter

Posted on 2006-06-22
2
Medium Priority
?
268 Views
Last Modified: 2012-06-21
hi,

is there a simple way to add pre-zero's to an integer?

i want to count till 1000 but i do not want to just count from 1 to 1000, i want to count from 0001 to 1000.
i know i can do this the long way by checking its length and for each length that its smaller then 4 add a 0 infront.
but i was wondering if there was an easy way for it.
0
Comment
Question by:PatrickAdrichem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 200 total points
ID: 16957781
Hi PatrickAdrichem,

How about using:

$num = 1;
$str_num = str_pad($num, 4, '0', STR_PAD_LEFT);

And then use intval() when you need to increment

Regards,
Zyloch
0
 
LVL 5

Author Comment

by:PatrickAdrichem
ID: 16957805
works perfectly thanks!!

this is what i needed it for:

http://www.bodyvitaal.nl/new/onderzoek/admincp/colourchart.php
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

741 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