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 if...else Statements
PHP - The if...else Statement The if...else statement executes some code if a...
بواسطة PHP Tutorial 2024-05-17 07:46:12 0 4كيلو بايت
أخرى
PHP Magic Constants
PHP Predefined Constants PHP has nine predefined constants that change value depending on where...
بواسطة PHP Tutorial 2024-05-17 07:40:16 0 5كيلو بايت
أخرى
PHP Variables
Variables are "containers" for storing information. Creating (Declaring) PHP Variables In...
بواسطة PHP Tutorial 2024-05-17 07:16:59 0 7كيلو بايت
أخرى
PHP Add Array Items
Add Array Item To add items to an existing array, you can use the bracket [] syntax....
بواسطة PHP Tutorial 2024-05-17 08:06:05 0 7كيلو بايت
أخرى
PHP Constants
Constants are like variables, except that once they are defined they cannot be changed or...
بواسطة PHP Tutorial 2024-05-17 07:39:53 0 8كيلو بايت
Sociallez https://sociallez.com