PHP – for Loop

For loop is a control Statement .

for (init counter; test counter; increment counter) {
code to be executed;

In for loop there are 3 section.

  • init counter
  • test counter
  • increment counter

The init counter is Used for Intialize Because it is Executed only once.

The test counter Check the Condition.Here we Write Expression which can be Executed Multiple Times.

The increment counter is Used for Increasing or Decreasing the value of a variable or we can Write any Expression.It is also Executed Several Times.


echo "$a <br>";

PHP foreach loop
foreach loop is a special type of control statement which is used for array .

it access all the elements in an array .


foreach ($array as $value) {
code to be executed;

Example Foreach

foreach($data as $element)
echo "$element";