PHP For Loop

When you need to do the same script many times, for exemple you want to send emails to all your users, you don't need to write a php code for each user, you just need to use for Loop which will do it for each one.
This is how:
for ($userid=1;$userid<=10;$userid++){

Where send_email() is your own function that send the email to the user with the id as parameter.

Another exemple to For Loop, let's say you want to count 1+2x2+3x3+...+nxn, this is how you can do it:
for ($i=1;$i<=$n;$i++){
$t+=$i*$i; // the same as $t=$t+$i*$i

So how For loop works ?

1. Set a counter variable to some initial value (i.e $i=0).
2. Check to see if the conditional statement is true(i.e $i<=10).
3. Execute the code within the loop.
4. Increment a counter at the end of each iteration through the loop(i.e $i++, or $i+=1, ou $i=$i+1) .

And this is how to do it:
for ( initialize a counter; conditional statement; increment a counter){
do this code;

The php loop will help you a lot in php programming, and there are other ways to do loops other that For, like while.


Custom-Web-design said...

Great work...if you can give another example then it would be more easy to understand.

Cegonsoft said...

It's a nice example..

Jack said...

Quite worthwhile info, thank you for the article.
sex in office | cast aluminum | Toronto condos

rize wordpress said...

Our dedicated PHP Programmers have an appropriate mix of expertise and ability that gives you the choice to select most suitable professional/team for your project.

jaring safety said...

The article posted was very informative and useful
thanks for sharing.
jaring futsal , jaring futsal murah , jual jaring futsal , toko jaring futsal , agen jaring futsal ,
jaring golf , jual jaring golf , jaring golf murah , jaring polynet , tangga darurat , jaring truk ,
jaring cargo , jaring outbound , jual rumput futsal murah , jual rumput sintetis murah , tali tambang , cargo net ,
jaring tanaman , jaring kassa , jaring proyek , jaring bangunan , jaring gedung , jaring pengaman proyek ,
jaring pengaman bangunan , jaring pengaman gedung , jaring peneduh , jaring waring , kasa hijau , tangga darurat ,
jaring gawang futsal , jaring peneduh , jaring truk

Sathya G said...

this is really a very great blog. the information present in this blog will be very useful for us. thank you for sharing with us.
ROI Services in Chennai

Rahul Kumar said...

This is the best blog design and article. Very nice job. Thank you very much
Your design and pics of the blog is really nice.

php training

Pasang Iklan Gratis said...

It's really useful for me, thanks a lot.

Jeffy said...

Thank you for sharing such a nice and interesting blog with us. Hope it might be much useful for us. keep on updating...!!
seo company in india
digital marketing company in india
seo company in chennai
digital marketing company in chennai