In PHP programming, we are often required to repeat a block of code, instead of adding several almost equal lines in a script we can use loops to perform a task like this. PHP has three types of loop constructs that all do the same thing, repeat a block of code a number of times, FOR loop, DO loop and WHILE loop. There are other types that have specific function in array : FOREACH. With FOREACH, it will loops through a block of code for each element in an array.

The FOR loop provides a compact way to create a loop with a specified number of times. We use the FOR loop when we know in advance how many times a block of code should run or execute. The FOR loop is also known as definite loop and it’s preferred by most programmers because it’s more convenient to use. See following example performs the FOR loop. … continue reading : Basic Learning PHP : Looping.