PHP For-Each Loop

Last Updated On Saturday 9th Apr 2022

The foreach loop – Loops through a block of code for each element in an array.

	foreach ($array as $value) {
  code to be executed;
}
	
  • For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element.
	<?php
$curarr = array("Hello", "World", "from", "Earth");

foreach ($curarr as $value) {
  echo "$value <br>";
}
?>