foreach() function provides an easy way to scan arrays & exactly do the same thing like for loop, so this function is said to be PHP foreach loop. foreach loop works only on arrays.
Syntax:
foreach ($arrayname as $value) {}
Example:
In the below example, element of extension array is assigned to variable $x & array pointer is increment by one, until it reaches the last element of array.
<?php
$extension = array("com", "in", "co", "net");
foreach ($extension as $x) {
echo "$x <br>";
}
?>
Output: com, in, co, net
0 Comment(s)