PHP foreach loop

The foreach loop is mainly used for looping through the values of an array. It loops over the array, and each value for the current array element is assigned to $value, and the array pointer is advanced by one to go the next element in the array.

Syntax:
<?php 
foreach (array as $value){ 
  //code to be executed; 
} 
?>
Example:
<?php
$salary[]=2000;
$salary[]=3000;
$salary[]=5000;

foreach($salary as $value){
  echo "Salary: $value<br>";
}
?>
Program Output:
Salary: 2000

Salary: 3000

Salary: 5000