PHP Loops

0
4KB

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.

Rechercher
Catégories
Lire la suite
Autre
PHP Comments
Comments in PHP A comment in PHP code is a line that is not executed as a part of the program....
Par PHP Tutorial 2024-05-17 07:14:49 0 6KB
Autre
PHP Create Arrays
Create Array You can create arrays by using the array() function: ExampleGet your...
Par PHP Tutorial 2024-05-17 08:01:55 0 8KB
Autre
PHP Magic Constants
PHP Predefined Constants PHP has nine predefined constants that change value depending on where...
Par PHP Tutorial 2024-05-17 07:40:16 0 5KB
Autre
الثورة البلوكتشين وتحولاتها في الصناعات المختلفة
مقدمة: شهدت تقنية البلوكتشين ثورة هائلة في السنوات الأخيرة، حيث أصبحت لديها القدرة على تغيير...
Par MOHAMED ATTALLAH 2024-05-14 14:03:03 0 7KB
Autre
PHP Casting
Sometimes you need to change a variable from one data type into another, and sometimes you want a...
Par PHP Tutorial 2024-05-17 07:38:02 0 4KB
Sociallez https://sociallez.com