PHP Loops

0
2KB

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.

Search
Nach Verein filtern
Read More
Other
PHP do while Loop
The do...while loop - Loops through a block of code once, and then repeats the loop as...
Von PHP Tutorial 2024-05-17 07:49:22 0 2KB
Other
PHP echo and print Statements
With PHP, there are two basic ways to get output: echo and print. In this...
Von PHP Tutorial 2024-05-17 07:20:06 0 2KB
Other
PHP Introduction
PHP code is executed on the server. What You Should Already Know Before you continue you...
Von PHP Tutorial 2024-05-17 07:08:40 0 2KB
Other
PHP Break
The break statement can be used to jump out of different kind of loops. Break in For...
Von PHP Tutorial 2024-05-17 07:50:37 0 2KB
Other
PHP Arrays
An array stores multiple values in one single variable: ExampleGet your own PHP Server $cars...
Von PHP Tutorial 2024-05-17 07:53:31 0 2KB