FOREACH ($array _variable as $value)
{
[Code to execute]
}
Or
FOREACH ($array _variable as $key => $value)
{
[Code to execute]
}
In both cases, multiple [code executions] will be executed equal to the number of elements in the $ array_variable array.
Let's take a look at an example. Let's say we have the following code snippet:
$array 1 = array (1,2,3,4,5);
FOREACH ($array 1 as $ABC)
{
Print "New value is". $abc *10. "<br>";
}
Output results
New value is 10
New value is 20
New value is 30
New value is 40
New value is 50
The Foreach loop goes through the array $ array1 of all 5 elements, each time printing out a statement containing 10 times times the value of the array element.
The foreach action is to iterate through all the values of the current array and assign it to $var.
Let's look at a foreach. Instance of multidimensional data operation
$s = array (array (1,2), array (3,4), Array (5,6));
foreach ($s as $v => $_v)
{
foreach ($_v as $VC => $_vc)
&nbs p; {
echo $_vc[0], ' | '. $_vc[1], ' <br/> ';
//print_r ($_VC);
}
}
This article is original in Www.111cn.net Reprint annotated Origin
*/