More commonly used for foreach
Copy the Code code as follows:
$price =array (' Apple ' =>10, ' orange ' =>20, ' banner ' =>30);
foreach ($price as $key = $value)
{
echo $key. ' = '. $value. '
';
}
Echo '
';
?>
There's a more advanced and common approach.
Copy the Code code as follows:
$shuiguo =array (' Apple ' =>10, ' orange ' =>20, ' banner ' =>30);
while (list ($changpin, $jiage) =each ($shuiguo))
{
echo "$changpin = $jiage".
';
}
?>
In the past, really did not pay much attention to, today's own hands, but also good, and understand the new things, or their own too food, hey
The list () function can be used to decompose an array into a series of values that allow for the naming of new variables. Do not understand the list of click here
The output of the two pieces of code is the same.
It is important to note that when using the each () function, the array will record the current element. If you want to use the array two times in the same script. It is necessary to reset the current element to the beginning of the array using the Reset () drop.
Copy the Code code as follows:
$price =array (' Apple ' =>10, ' orange ' =>20, ' banner ' =>30);
foreach ($price as $key = $value)
{
echo $key. ' = '. $value. '
';
}
Echo '
';
Reset ($price);
while (list ($key, $value) =each ($price))
{
echo "$key = $value", "
";
}
?>
This allows you to still use the array $price.
Some books, as a novice I, I do, knock down to see the effect, understand, write a post, easy to forget to look at later, said the relatively superficial, poor language expression, laughed at.
Copy the Code code as follows:
/*
Looping statements in *php learning notes
* One. While loop
if (an expression)
Executes only one statement at a time.
while (expression) {
Repeated execution of the loop body;
}
* Two. Do-while cycle
* Three. For loop
* There are two types of loops depending on the cycle condition
* One: Count loop for
* Another type: conditional loop while Do-while//foreach
* Several statements related to loops
*break;//can be used for process control and loop bodies to jump out of the loop.
continue;//can only be used for loop bodies, exiting this cycle. Exit
Return
* Write loops try not to exceed three layers.
* Loop the flow control statement as far as possible not more than five layers.
*/
$num = 0;
while ($num <100) {
echo "This is the result of executing the {$num} secondary output
";
$num + +;
}
//
Echo '
align= "center" > "; Echo '
Using a while loop output
Out of the table
'; $i = 0; while ($i <1000) {if ($i%10==0) {if ($i%20==0) {$bg = "#ffffff";} else{$BG = "#cccccc";} Echo '
Bgcolor= "'. $bg. ' > '; } Echo '
'. $i. ' | '; $i + +; if ($i%10==0) {echo ';}} Echo '
';
//
$i = 0;
do{
echo "$i: This is Do*while
";
$i + +;
}while ($i <10);
//
for (initialized condition; conditional expression; increment) {
Circulation body;
}
/*
The Do-while loop is to execute the code once, then judge, and
The while loop is the first to judge if it is true to continue the loop,
False does not loop.
*/
99 Multiplication Table
for ($i =1; $i <=9; $i + +) {
for ($j =1; $j <= $i; $j + +) {
echo "$j x $i =
". $j * $i." ";
}
Echo '
';
The above describes the four leaf clover PHP Loop statement Note Foreach,list, including the four Leaf clover aspects of the content, I hope the PHP tutorial interested in a friend helpful.