Ec (2); a foreach loop is a variant For loop that allows you to traverse elements in the array. There are two different versions of foreach loops. The syntax of the foreach loop is as follows: foreach (arrayasvalue) {& nbsp; codetobeexecuted ;}& nbsp; & nbsp; foreach (arrayaskey & gt; value) {script ec (2); script
A foreach loop is a variant For loop that allows you to traverse elements in the array. There are two different versions
Foreach loop. The syntax of the foreach loop is as follows:
Foreach (array as value)
{
Code to be executed;
}
Foreach (array as key => value)
{
Code to be executed;
}
The following example demonstrates a foreach loop that prints the value of a given array:
$ Email = array ('John. smith@example.com ', 'Alex @ example.com ');
Foreach ($ email as $ value ){
Echo "Processing". $ value ."
";
}
?>
PHP executes each element in USD. In turn, the email body is cyclically sent once, and the dollar value is set to the current element. Element
Handle the domestic order. Continues until the last element of the foreach loop or the approx. of the given array is reached.
.
$ Person = array ('name' => 'Andrew ', 'age' => 21, 'address' => '77, Lincoln
St .');
Foreach ($ person as $ key => $ value ){
Echo $ key. "is". $ value ."
";
}
?>
In this case, the key to each element is placed in the $ key and the corresponding value is $.
In foreach, construct a non-business array, but a copy of it. In each loop, the value of the variable $ value can be
Operation, but the original value of the array remains unchanged.