PHP Foreach Loop

The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects.

Syntax


<?php
	foreach (array_variable as value) 
	{ 
	  code to be execute]
	}
?>								
							

Example


<?php

$x=array("Tutorials","Computer","Online Tools");
foreach($x as $value)
{
	echo $value."
"; } ?>

Output


Tutorials
Computer
Online Tools							
							
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!