The loop in PHP is a sequence of instruction that is continually
repeated until a certain condition is reached. PHP support 4 types of
lops
- For loop:- A for php loop statements allows a number of lines represented until the condition is satisfied. In this no need to initialize variable before the loop.
- Syntax of For loop:-
| For (initialize counter variable,condition){// statement 1// // statement n } |
- While loop:- A while loop statement allows a number of lines represented until the condition is satisfied. In this to initialize the variable before the loop increment/decrement the variable within the loop.
- Syntax of While loop:-
| .While (condition){//statement 1// //statement n } |
- Do-While:- A Do-while loop statement allows a number of lines represented until the condition is satisfied.Once it execute if the condition is true/false, first execute the statement then it checks for condition.
- Syntax of Do-While loop:-
| do{//statement 1// //statement n } While (condition); |
- For each loop:- In this php loop tutorial every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element.
- Syntax of For each loop:-
| foreach (array as value) { //statement 1;} |
No comments:
Post a Comment