Loops in PHP
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
A Loop is an Iterative Control Structure that involves executing the same number of code a number of times until a certain condition is fulfilled
Types of Loops in PHP
- while
- do-while loop
- for loop
- foreach loop
1 . While :-The while loop is an entry control loop like for loops i.e., it first check the condition at the start of the loop and if its true then it enters the loop and executes the block of statement which is under block, and goes on executing it as long as the condition will true.
2 . DO- WHILE LOOP :- The block of code executed once and then condition is checked. If the condition is true the statement is repeated as long as the specified condition is true and if the condition will be false in first itteration then also the statement will be executed first time .
3 . FOR LOOP :- For loop is commonly used to execute a code block a specific number of times. The syntax makes use of three expressions:
4 . FOREACH LOOP :-We use foreach loop mainly for loop through the value of an array. It loops over the array, and each value for the current array element is assigned to value, and the array pointer is advanced by one to go the next element in the array. Though foreach loop iterates over an array of elements.