/* */ Click to Join Live Class with Shankar sir Call 9798158723

PHP foreach construct ?


for each construct works only on arrays. The foreach looping is the best way to access each key value pair from an array.


Syntax:-
For each (array_expr as $key => $value)
{
statement
}

Note:

array_expr is an array. In every loop the value of the current element of the array is assigned to $value and the internal array pointer is advanced by one and the process continue to reach the last array element.

foreach construct program.
 <?php
 $fruits = array ("Orange", "Apple", "Banana", "Cherry", Mango");
 foreach ( $fruits as $value )
 {
 echo "$value<br />";
 }
 ?>