for loop
Grammar rules:
for(初始化计数初值;判断条件;增加计数值){ 循环体; }
Example:
Execution results: (Recommended learning: PHP programming from entry to proficiency)
0 1 2 3 4
while loop
Grammar rules
while(判断条件){ 循环体; }
The while loop first judges the loop condition and then loops. When the condition is not met, break out of the loop.
Note: Increase the count value, otherwise it will enter an infinite loop.
Example:
Execution result:
0 1 2 3 4
do while loop
Grammar rules
do{ 循环体; }while(判断条件);
do while loop first enters the loop and then determines the loop condition. So no matter whether the judgment condition is true or false, there will be at least one loop.
Example:
Execution result:
0 1 2 3 4
foreach loop
Grammar rules
foreach($array as $value){ 执行代码; }
or
foreach($array as $key => $value ){ 执行代码; }
$array: array $value: array key value $key: array key name.
foreach is used for array traversal. Each time a loop is performed, the current value is assigned to the $value variable, and the array pointer moves one by one until the last element.
Example:
Execution result:
The above is the detailed content of What are the loop statements in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
