The foreach loop - Loops through a block of code for each element in an array.
foreach (array_expression as $value) statement foreach (array_expression as $key => $value) statement
$array = array('PHP','JS','CSS','HTML'); foreach($array as $value) { echo $value.PHP_EOL; } //output: PHP JS CSS HTML
We can get the array key as well as value of it
$array = array('lang1'=>'PHP','lang2'=>'JS','lang3'=>'NodeJS'); foreach($array as $key=>$value) { echo $key.'::'.$value.PHP_EOL; } //output: lang1::PHP lang2::JS lang3::NodeJS