The foreach statement is a looping construct used in PHP to iterate and loop through the array data type. The working of foreach is simple; with every single pass of the value, elements get assigned a value and pointers are incremented. This process is repeated until the end of the array.
The following is the syntax for using the foreach statement in PHP:
foreach(array)
{
Code inside the loop;
}