/    Sign up×
Community /Pin to ProfileBookmark

looping and echo()||alert()

Hi!

I apologise for keeping on making the comparison to javascript but i think it would be easier to explain this way.
For instance in javascript you can do this:

[code]
for(i=0;i<12;i++){
alert(i)
}
[/code]

and it will cycle through the code alerting the value of i. what would be the way to this in php. e.g:

[code=php]

for ($i = 1; $i <= 10; $i++) {
//is there an alert or would this have to do
echo $i;
}

[/code]

Thank-you

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvJun 13.2004 — It'll work just the same way in PHP. In fact it'll work just the same in any language that supports a [font=courier]for[/font] loop construct. Of course the only difference being the JavaScript version outputs the value in alert dialogs where the PHP version outputs the value as literal text.
Copy linkTweet thisAlerts:
@olafJun 14.2004 — Use this: [code=php]
for ($i = 1; $i <= 10; $i++) {
//is there an alert or would this have to do
echo "<script>alert(".$i.")</script>";
}


[/code]
×

Success!

Help @Naemo 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...