PHP Loops

0
2χλμ.

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 Associative Arrays
PHP Associative Arrays Associative arrays are arrays that use named keys that you assign to...
από PHP Tutorial 2024-05-17 08:01:14 0 4χλμ.
άλλο
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 2χλμ.
άλλο
PHP - $_SERVER
$_SERVER $_SERVER is a PHP super global variable which holds information about headers,...
από PHP Tutorial 2024-05-17 08:08:50 0 4χλμ.
άλλο
PHP Math
PHP has a set of math functions that allows you to perform mathematical tasks on numbers. PHP...
από PHP Tutorial 2024-05-17 07:39:09 0 3χλμ.
άλλο
PHP while Loop
The while loop - Loops through a block of code as long as the specified condition is...
από PHP Tutorial 2024-05-17 07:48:58 0 2χλμ.