/*
For syntax
| The code is as follows |
Copy Code |
for (EXPR1; expr2; expr3) {
Statement
} |
See the For instance tutorial below
*/
| The code is as follows |
Copy Code |
$for = Array (1,2,3,4,5,6);
$forFor = Array (
Array (1),
Array (2),
Array (3)
);
|
Let's take a look at an instance of a set of data with a for loop
| The code is as follows |
Copy Code |
|
$arrayLen = sizeof ($for);
for ($i = 0; $i < $arrayLen; $i + +)
{
echo $for [$i], ' <br> ';
} |
/*
Results
1
2
3
4
5
6
This is the result we want.
For to process a two-dimensional array
| The code is as follows |
Copy Code |
*/
for ($j =0; $j < $arrayLen; $j + +)
{
Echo ($forFor ($j));
} |
Fatal error:function name must being a string in hint appears
Let's switch to a different user with a foreach instance.
| The code is as follows |
Copy Code |
foreach ($forFor as $v => $vv)
{
Print_r ($VV);
} |
/*
Output
(
[0] => 1
)
Array
(
[0] => 2
)
Array
(
[0] => 3
)
Exactly the data we want,
Summarize
Each statement has its own purpose, and we want to see how it is more reasonable to use functions that are appropriate for your current operation to do your work quickly.
From the above, for the one dimensional data, and a single loop, foreach can manipulate one-dimensional data in two-dimensional data.
This site original article reproduced annotated from www.111cn.net/phper/php.html