The following is a concept of iterating through an array using the foreach while for Three loop
1:foreach ()
<?php
$a = Array (' Hank ', ' Mike ', ' Lucy ');
foreach ($a = $v) {
echo "Do-like $v". " <br/> ";
}
2:while ()
while () is often used with list () each ()
<?php
$a = Array (' Mike ', ' Hank ', ' Lucy ');
while (list ($key, $val) =each ($a)) {
echo "Do-like $val <br/>";
}
3:for ()
$a = Array (' Hank ', ' Mike ', ' Lucy ');
for ($i =0; $i <count ($a); $i + +) {
echo "$a [$i]." <br/> ";
}
-------------------------------------------
Introduce list () and each ()
#list () assigns a set of variables to an array of elements
Example
<?php
$a =array (' Mike ', ' Hank ', ' Lucy ');
List ($x, $y, $z) = $a;
echo $x;
Echo $y;
Echo $z;
#each ()
Displays the elements (keys and values) in an array in two sets of indexed and associative arrays, respectively.
Example
<?php
$a = Array (' Mike ', ' Hank ', ' Lucy ');
Print_r (each ($a));
Print_r (each ($a));
Print_r (each ($a));
Each time the pointer to the array is down one bit.
PHP traversal array for foreach while