Foreach Loop
The foreach loop works only on arrays, and is used to loop through each key/value pair in an array. There are two syntaxes:
$students = array ('Elena', 'Nia', 'Zura');

foreach ($students as $student) {
    echo $student . "\n";
}
/*Outputs:
Elena
Nia
Zura*/
$age = array ("Elena" => "39", "Nia" => "11", "Zura" => "41");

foreach ($age as $x => $val) {
    echo "$x = $val" . "\n";
}

/*Outputs:
Elena = 39
Nia = 11
Zura = 41*/
by Elena Kuparadze
2 years ago
PHP
Loop
0
Pro tip: use ```triple backticks around text``` to write in code fences