PHP: for - Manual in Deutsh
PHP: for - Manual in French
PHP: for - Manual in Polish

You Are At PHP: for - Manual Area


recent searches:
include functions , variable functions , post functions...




If you are new to PHP or just need to refresh your skills, this is the place to start. This series of tutorials will give you the basic knowledge you will need to create a simple PHP website.

PHP is a reflective programming language originally designed for producing dynamic web pages.[1] PHP is used mainly in server-side scripting, but can be used from a command line interface or in standalone graphical applications. Textual User Interfaces can also be created using ncurses.

PHP Manual
PrevChapter 16. Control StructuresNext

for

for loops are the most complex loops in PHP. They behave like their C counterparts. The syntax of a for loop is:

for (expr1; expr2; expr3)
    statement

The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.

In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends.

At the end of each iteration, expr3 is evaluated (executed).

Each of the expressions can be empty or contain multiple expressions separated by commas. Comma separated expressions in expr2 are treated similarly to being separated by the || operator but has a lower precedence than ||. expr2 being empty means the loop should be run indefinitely (PHP implicitly considers it as TRUE, like C). This may not be as useless as you might think, since often you'd want to end the loop using a conditional break statement instead of using the for truth expression.

Consider the following examples. All of them display numbers from 1 to 10:

<?php
/* example 1 */

for ($i = 1; $i <= 10; $i++) {
    echo
$i;
}

/* example 2 */

for ($i = 1; ; $i++) {
    if (
$i > 10) {
        break;
    }
    echo
$i;
}

/* example 3 */

$i = 1;
for (; ; ) {
    if (
$i > 10) {
        break;
    }
    echo
$i;
    
$i++;
}

/* example 4 */

for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
?>

Of course, the first example appears to be the nicest one (or perhaps the fourth), but you may find that being able to use empty expressions in for loops comes in handy in many occasions.

PHP also supports the alternate "colon syntax" for for loops.

for (expr1; expr2; expr3):
    statement
    ...
endfor;

Wyjatkowej jakości meble medyczne w xmebel
Kotły gazowe
Grzejniki
zespół weselny warszawa
Największa baza pytań egzamin doradca podatkowy testy na doradce podatkowego

Another Useful functions:


zend-api.zend-hash-move-forward | zend-api.zend-hash-move-forward-ex | zend-api.open-file-for-scanning | tutorial.forms | security.cgi-bin.force-redirect | ref.pdo-informix | ref.pdo-informix.connection | function.xsl-xsltprocessor-transform-to-xml | function.xsl-xsltprocessor-transform-to-uri | function.xsl-xsltprocessor-transform-to-doc | function.swf-actionwaitforframe | function.stats-rand-gen-iuniform | function.stats-rand-gen-funiform | function.stats-den-uniform | function.stats-cdf-uniform | function.snmp-set-oid-output-format | function.pcntl-fork | function.odbc-foreignkeys | function.number-format | function.newt-wait-for-key | function.newt-run-form | function.newt-grid-add-components-to-form | function.newt-form | function.newt-form-watch-fd | function.newt-form-set-width | function.newt-form-set-timer | function.newt-form-set-size | function.newt-form-set-height | function.newt-form-set-background | function.newt-form-run | function.newt-form-get-current | function.newt-form-destroy | function.newt-form-add-hot-key | function.newt-form-add-components | function.newt-form-add-component | function.newt-draw-form | function.money-format | function.lzf-optimized-for | function.ircg-register-format-messages | function.ircg-lookup-format-messages | function.imagick-transformrgb | function.imagecolorsforindex | function.ifx-nullformat | function.httprequestpool-socketperform | function.fdf-set-submit-form-action | function.domnode-insert-before | function.dom-domnode-insertbefore | function.db2-foreign-keys | function.date-format | function.cybermut-creerformulairecm | | features.xforms | control-structures.foreach | control-structures.for |


PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. If you are new to PHP and want to get some idea of how it works, try the introductory tutorial. After that, check out the online manual, and the example archive sites and some of the other resources available in the links section.