PHP Loops

Loops are used to execute a code till a specific condition/counter.

PHP Supports four type of Loops

  • For Loop
  • While Loop
  • Do...While Loop
  • Foreach Loop

For Loop

For Loop executes a code till the specified number.


<?php
	for($a=0;$a<11;$a++){
		echo $a."<br>";
	}
?>
	

Foreach Loop

Foreach loop only works on arrays. and is used to loop through each key/value in an array


<?php
	$color=array("white","green","black","blue","ornage","pink");
	foreach($color as $value){
		echo $value."<br>";
	}
?>