Learn Before
Concept
PHP Loops
When writing code, you frequently want a particular block of code to run a given number of times repeatedly. Thus, we can use loops in a script rather than adding numerous nearly identical code lines.
Loops are used to repeatedly run the same block of code as long as a specific condition is met.
We have the following sorts of loops in PHP:
- while - loops through a block of code as long as the specified condition is true
- do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true
- for - loops through a block of code a specified number of times
- foreach - loops through a block of code for each element in an array
0
1
Updated 2023-02-06
Tags
Object-Oriented Programming (OOP) Languages