how to create a php looping

78 downloads 124 Views 297KB Size Report
09/11/12 17:27. PHP Looping For loops. Page 1 sur 3 http://www.w3schools.com/ php/php_looping_for.asp. Search w3schools.com. Search. Sélectionner une ...
PHP Looping For loops

09/11/12 17:27

Sélectionner une langue ​ ▼ Search w3schools.com HOME

HTML

CSS

JAVASCRIPT

JQUERY

XML

ASP.NET

PHP

SQL

MORE...

Search

REFERENCES | EXAMPLES | FORUM | ABOUT

W3SCHOOLS BOOKS New Books: HTML, CSS JavaScript, and Ajax

PHP Basic PHP HOME PHP Intro PHP Install PHP Syntax PHP Variables PHP String PHP Operators PHP If...Else PHP Switch PHP Arrays PHP While Loops PHP For Loops PHP Functions PHP Forms PHP $_GET PHP $_POST

PHP Advanced PHP PHP PHP PHP PHP PHP PHP PHP PHP PHP PHP

Date Include File File Upload Cookies Sessions E-mail Secure E-mail Error Exception Filter

PHP Database MySQL Introduction MySQL Connect MySQL Create MySQL Insert MySQL Select MySQL Where MySQL Order By MySQL Update MySQL Delete PHP ODBC

PHP XML XML Expat Parser XML DOM XML SimpleXML

PHP and AJAX AJAX AJAX AJAX AJAX AJAX AJAX AJAX

Intro PHP Database XML Live Search RSS Reader Poll

PHP Reference PHP PHP PHP PHP PHP PHP PHP PHP PHP PHP PHP PHP

Array Calendar Date Directory Error Filesystem Filter FTP HTTP Libxml Mail Math

PHP Looping - For Loops « Previous

w3schools.com on Facebook

Next Chapter »

Loops execute a block of code a specified number of times, or while a specified condition is true.

J’aime

10 k

WEB HOSTING Best Web Hosting PHP MySQL Hosting UK Reseller Hosting

The for Loop

Cloud Hosting

The for loop is used when you know in advance how many times the script should run.

Top Web Hosting $3.98 Unlimited Hosting

Syntax

250+ Hosting Apps

for (init; condition; increment) { code to be executed; } Parameters:

WEB BUILDING Download XML Editor FREE Website BUILDER FREE Website Creator W3SCHOOLS EXAMS

init: Mostly used to set a counter (but can be any code to be executed once at the beginning of the loop) condition: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends. increment: Mostly used to increment a counter (but can be any code to be executed at the end of the iteration) Note: The init and increment parameters above can be empty or have multiple expressions (separated by commas).

Example The example below defines a loop that starts with i=1. The loop will continue to run as long as the variable i is less than, or equal to 5. The variable i will increase by 1 each time the loop runs:

Get Certified in: HTML, CSS, JavaScript, jQuery, XML, PHP, ASP W3SCHOOLS BOOKS New Books: HTML, CSS JavaScript, and Ajax STATISTICS Browser Statistics Browser OS Browser Display SHARE THIS PAGE

Output:

The The The The The

number number number number number

is is is is is

1 2 3 4 5

The foreach Loop The foreach loop is used to loop through arrays.

Syntax foreach ($array as $value) { code to be executed;

http://www.w3schools.com/php/php_looping_for.asp

Page 1 sur 3

PHP Looping For loops PHP PHP PHP PHP PHP PHP

Misc MySQL SimpleXML String XML Zip

PHP Quiz PHP Quiz PHP Certificate

09/11/12 17:27

} For every loop iteration, the value of the current array element is assigned to $value (and the array pointer is moved by one) - so on the next loop iteration, you'll be looking at the next array value.

Example The following example demonstrates a loop that will print the values of the given array:

Output:

one two three

« Previous

Next Chapter »

22,756,521 Sites Built with Wix Click here to make yours for free. Wix.com is a powerful online platform that lets anyone design and publish professional, beautiful HTML5 websites for free, without touching a line of code. With revolutionary drag & drop editing tools, eCommerce features and superior search engine results, Wix offers infinite web design possibilities, while saving you tons of money.

Altova® MapForce® Graphical XML Conversion Tool from the Developers of XMLSpy®

Need an easy way to get data into XML, or transform XML to another format? MapForce lets you map XML data to/from any combination of XML, database, flat file, Excel 2007, XBRL, or Web services data. Then it transforms data instantly or auto-generates royalty-free code for recurrent conversions. New features in Version 2013! Easy-to-use, graphical data mapping interface Instant data transformation XSLT 1.0/2.0 and XQuery code generation Java, C#, and C++ code generation Advanced data processing functions Support for all major relational databases including SQL Server, IBM DB2, Oracle, and more Integration with Altova StyleVision for report rendering Visual Studio & Eclipse integration Available in 32-bit and 64-bit versions

Try it now!

Download a fully-functional trial today!

http://www.w3schools.com/php/php_looping_for.asp

Page 2 sur 3

PHP Looping For loops

09/11/12 17:27

W3Schools' Online Certification The perfect solution for professionals who need to balance work, family, and career building. More than 10 000 certificates already issued!

Get Your Certificate » The HTML Certificate documents your knowledge of HTML. The CSS Certificate documents your knowledge of advanced CSS. The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM. The jQuery Certificate documents your knowledge of jQuery. The XML Certificate documents your knowledge of XML, XML DOM and XSLT. The ASP Certificate documents your knowledge of ASP, SQL, and ADO. The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

Top 10 Tutorials

Top 10 References

Examples

Quizzes

» » » » » » » » » »

» » » » » » » » » »

» » » » » » » » » » »

» » » » » » » » »

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial JavaScript Tutorial jQuery Tutorial SQL Tutorial PHP Tutorial ASP.NET Tutorial XML Tutorial

HTML/HTML5 Reference CSS 1,2,3 Reference CSS 3 Browser Support JavaScript HTML DOM XML DOM PHP Reference jQuery Reference ASP.NET Reference HTML Colors

HTML Examples CSS Examples XML Examples JavaScript Examples HTML DOM Examples XML DOM Examples AJAX Examples ASP.NET Examples Razor Examples ASP Examples SVG Examples

Color Picker

HTML Quiz XHTML Quiz CSS Quiz JavaScript Quiz jQuery Quiz XML Quiz ASP Quiz PHP Quiz SQL Quiz

Statistics » Browser Statistics » Browser OS » Browser Display

REPORT

ERROR

|

HOME

|

TOP

|

PRINT

|

FORUM

|

ABOUT

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2012 by Refsnes Data. All Rights Reserved.

http://www.w3schools.com/php/php_looping_for.asp

Page 3 sur 3