PHP foreach loop

The foreach loop - Loops through a block of code for each element in an array.

There are two syntaxes:

foreach (array_expression as $value)
foreach (array_expression as $key => $value)

Example- 1 first Syntax

$array = array('PHP','JS','CSS','HTML');
foreach($array as $value)
	echo $value.PHP_EOL;
//output: PHP JS CSS HTML 

Example- 2 Second Syntax

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