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.

foreach (array as $value){ 
  //code to be executed; 

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

Salary: 3000

Salary: 5000

Subscribe Updates via Email

Join 49,000+ W3schools lovers and get all the latest tutorials, programs, algorithms in your inbox.