/    Sign up×
Community /Pin to ProfileBookmark

loop thru string

i have a string for ex:
“2,5,9,12,23,38,39”

what i want to do is have a for loop where i can pull out a number on each pass. so the first pass would be 2, the second pass 5, etc. how would i do this?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 07.2007 — [code=php]<?php
$string = "2,5,9,12,23,38,39";
$tok = strtok($string, ',');
while($tok !== FALSE)
{
echo $tok."<br />n";
$tok = strtok(',');
}
?>[/code]
Copy linkTweet thisAlerts:
@ripken204authorAug 07.2007 — i ended up using

$array=split(',' , "2,5,9,12,23,38,39")
Copy linkTweet thisAlerts:
@pcthugAug 07.2007 — [code=php]
$array = explode(',', "2,5,9,12,23,38,39");
[/code]


Will give the exact same results, minus the added overhead of using regular expressions ([i]split()[/i])
×

Success!

Help @ripken204 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.20,
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,
)...