/    Sign up×
Community /Pin to ProfileBookmark

counting with three digits

hi all,

i have a situation where i need to dynamically generate a list of numbers in PHP, but i can’t just use something like count++, because i need to search the list later using substring() in javascript, which requires i know which characters to search. in other words, i need PHP to generate a list that looks like this:

001
002
003

034
035

123
124

(for example)

hope that makes sense! thanks!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@pyroJan 05.2004 — Use [URL=http://us3.php.net/str_pad]str_pad()[/URL], something like this:

[code=php]<?PHP
for ($i=1; $i<=150; $i++) {
echo str_pad($i, 3, 0, STR_PAD_LEFT)."<br />";
}
?[/code]
Copy linkTweet thisAlerts:
@azazelauthorJan 05.2004 — excellent! thanks!

now, what would be the best way to implement something like the following? i'm creating a list of checkboxes, with each checkbox having a unique id, but falling within groups, like this:

[CODE]
<input type="checkbox" name="dl001grp001sub001">
[/CODE]


that would be a bottom level checkbox in a list that would look like this:

[CODE]
x dltop001
x dl001grp001
x dl001grp001sub001
x dltop002
x dl002grp001
x dl002grp001sub001
[/CODE]


hopefully this makes sense. thanks!
×

Success!

Help @azazel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...