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:
<?php
for ($userid=1;$userid<=10;$userid++){
send_email($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:
<?php
$n=10;
$t=0;
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.

23 comments:

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
https://tokojaring.wordpress.com/
https://jualjaringfutsal.wordpress.com/
https://pasangjaringfutsal.wordpress.com/
http://pancasamudera.wordpress.com/
http://jaringfutsal.wordpress.com/

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

kokila zenrays said...

Thanks for this informative blog. Good information about PHP loop. keep sharing nice blog. Best PHP training in Bangalore

Garrick Co Ida said...

PHP Training in Chennai
PHP Online Training India

Aptron said...

It's a nice example of PHP loop and that's a important part of PHP Course.

iClass Gyansetu said...

Salesforce Admin Certification Training Gurgaon,Delhi

Ancy merina said...

I like this blog, saved to my bookmarks.I have got some important suggestions from it.
Web Development Services in Bangalore
Website Design and Development Services in Bangalore
ECommerce Web Design Company in India
Outsource magento ecommerce services india

Saravanan said...

Language Interpretation Services, Voice Over Services India

Ram priya said...

I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 
Data science training in tambaram
Data science training in kalyan nagar
Data Science training in OMR
Data Science training in anna nagar
Data Science training in chennai
Data Science training in marathahalli
Data Science training in BTM layout
Data Science training in rajaji nagar

Nila shri said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

Deops training in annanagar

Devops training in chennai

Devops training in marathahalli

Devops training in rajajinagar

Devops training in BTM Layout

nivatha said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
Devops training in Chennai
Devops training in Bangalore
Devops training in Pune
Devops Online training
Devops training in Pune
Devops training in Bangalore
Devops training in tambaram

simbu said...

I simply want to give you a huge thumbs up for the great info you have got here on this post.



java training in chennai | java training in bangalore

java online training | java training in pune

selenium training in chennai

selenium training in bangalore

Rohini .R said...

Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision.
Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium online Training

pragya pragya said...

I'm here representing the visitors and readers of your own website say many thanks for many remarkable
python training in tambaram
python training in annanagar
python training in jayanagar

SRI said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

rpa interview questions and answers
automation anywhere interview questions and answers
blueprism interview questions and answers
uipath interview questions and answers
rpa training in chennai

Anonymous said...

This is good site and nice point of view.I learnt lots of useful information.
angularjs online Training

angularjs Training in marathahalli

angularjs interview questions and answers

angularjs Training in bangalore

angularjs Training in bangalore

angularjs Training in chennai