For Loops

   

For loops are useful constructions to loop through a finite set of data, such as data in an array:

 for($i = 0; $i < sizeof($array); $i++) {      //do something with array[$i]; } 

For loops require three things when they are defined:

  • Counter In the above example, $i = 0. You can pass in an already assigned variable or assign a value to the variable in the for statement.

  • The condition required to continue the for loop In the above example, while $i is less than the size of the $array, the for loop continues to be executed.

  • Statement to modify the counter on each pass of the loop In the above example, $i++ increments the counter after each loop.


   
Top


Advanced PHP for Web Professionals
Advanced PHP for Web Professionals
ISBN: 0130085391
EAN: 2147483647
Year: 2005
Pages: 92

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net