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.

Suche
Kategorien
Mehr lesen
Andere
PHP Access Arrays
Access Array Item To access an array item, you can refer to the index number for indexed arrays,...
Von PHP Tutorial 2024-05-17 08:02:32 0 8KB
Andere
PHP Multiline Comments
Multi-line Comments Multi-line comments start with /* and end with */. Any text...
Von PHP Tutorial 2024-05-17 07:15:48 0 6KB
Andere
تطورات التعلم الآلي وتأثيرها على مستقبل العمل
مقدمة: في ظل التطورات السريعة للتكنولوجيا والابتكار، أصبح التعلم الآلي...
Von MOHAMED ATTALLAH 2024-05-14 13:56:58 0 7KB
Andere
PHP Strings
A string is a sequence of characters, like "Hello world!". Strings Strings in PHP are...
Von PHP Tutorial 2024-05-17 07:28:17 0 6KB
Andere
PHP Constants
Constants are like variables, except that once they are defined they cannot be changed or...
Von PHP Tutorial 2024-05-17 07:39:53 0 8KB
Sociallez https://sociallez.com