PHP Loops
Posted 2024-05-17 07:48:35
0
2K
In the following chapters you will learn how to repeat code by using loops in PHP.
PHP Loops
Often when you write code, you want the same block of code to run over and over again a certain number of times. So, instead of adding several almost equal code-lines in a script, we can use loops.
Loops are used to execute the same block of code again and again, as long as a certain condition is true.
In PHP, we have the following loop types:
while
- loops through a block of code as long as the specified condition is truedo...while
- loops through a block of code once, and then repeats the loop as long as the specified condition is truefor
- loops through a block of code a specified number of timesforeach
- loops through a block of code for each element in an array
The following chapters will explain and give examples of each loop type.
Search
Categories
- Art
- Causes
- Crafts
- Dance
- Drinks
- Film
- Fitness
- Food
- Games
- Gardening
- Health
- Home
- Literature
- Music
- Networking
- Other
- Party
- Religion
- Shopping
- Sports
- Theater
- Wellness
Read More
PHP Casting
Sometimes you need to change a variable from one data type into another, and sometimes you want a...
PHP switch Statement
The switch statement is used to perform different actions based on different...
PHP Break
The break statement can be used to jump out of different kind of loops.
Break in For...
PHP Array Functions
PHP Array Functions
PHP has a set of built-in functions that you can use on arrays....
PHP - Concatenate Strings
String Concatenation
To concatenate, or combine, two strings you can use...