PHP Loops

0
4Кб

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 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

The following chapters will explain and give examples of each loop type.

Поиск
Категории
Больше
Другое
PHP Continue
The continue statement can be used to jump out of the current iteration of a loop, and...
От PHP Tutorial 2024-05-17 07:52:32 0 4Кб
Другое
PHP Sorting Arrays
The elements in an array can be sorted in alphabetical or numerical order, descending or...
От PHP Tutorial 2024-05-17 08:06:46 0 8Кб
Другое
PHP Nested if Statement
Nested If You can have if statements inside if statements, this is...
От PHP Tutorial 2024-05-17 07:47:26 0 4Кб
Другое
PHP Casting
Sometimes you need to change a variable from one data type into another, and sometimes you want a...
От PHP Tutorial 2024-05-17 07:38:02 0 4Кб
Другое
PHP Shorthand if Statements
Short Hand If To write shorter code, you can write if statements on one line....
От PHP Tutorial 2024-05-17 07:47:03 0 4Кб
Sociallez https://sociallez.com