The best PHP For loop Tutorial In 2024, In this tutorial you can learn for loop,foreach loop,
Loop executes a block of code a specified number of times, or when a specified condition is true loop code block is executed.
for loop is used to know in advance that you need to run the script is the number of times.
parameter:
Note: Theinitial valueandincrementparameters above can be empty or have multiple expressions (separated by commas).
The following examples define an initial value i = 1 cycle. As long as the variableiis less than or equal to 5, the loop will continue to run. Each time you run cycle, the variableiis incremented 1:
Output:
foreach loop through the array is used.
Once every cycle, the current value of the array element will be assigned to $ value variable (array pointer will move one by one), during the next cycle, you will see the next value in the array.
The following example shows an output value of a given array of loops:
Output: