more commonly used for foreach
<?php $price =array (' Apple ' =>10, ' orange ' =>20, ' banner ' =>30); foreach ($price as $key = + $value) {echo $key. ' = '. $value. ' <br> '; } echo ' <br> ';?>
There's a more advanced and common approach.
<?php $shuiguo =array (' Apple ' =>10, ' orange ' =>20, ' banner ' =>30); while (list ($changpin, $jiage) =each ($shuiguo)) {echo "$changpin = = $jiage". <br> '; }?>
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 Two code output 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.
<?php $price =array (' Apple ' =>10, ' orange ' =>20, ' banner ' =>30); foreach ($price as $key = + $value) {echo $key. ' = '. $value. ' <br> '; } echo ' <br> '; Reset ($price); while (list ($key, $value) =each ($price)) {echo "$key + = $value", "<br>";}?>
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.
<?php/* *php in the looping statements in the learning notes * one. The while loop if (expression) executes only one statement at a time. while (expression) {Executes the loop body repeatedly;} * two. do-while loop * three. For loop * There are two types of loops depending on the loop condition * One: Count loop for * Another: conditional loop while Do-while//foreach * several and loops The relevant statement *break;//can be used for process control and loop bodies, jumping out of loops. 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 performing the {$num} output <br>"; $num + +;}//Echo ' <table border= "1" width= "align=" Cente R ">"; Echo ' <caption>