Example of foreach and list loop statements in php. The article focuses on the usage of foreach loop and list loop statements. let's take a look at the implementation below. if you need more, you can refer to it. I recently bought an article to focus on the usage of the foreach loop and list loop statements. let's take a look at the implementation below. if you need more, let's take a look at it.
I recently bought php and mysql web development and saw the array loop statements. It is worth your attention and I will keep some handwriting for later reading.
Generally, foreach uses more
| The code is as follows: |
|
|
$ Price = array ('apple' => 10, 'Orange '=> 20, 'banner' => 30 );
Foreach ($ price as $ key => $ value)
{
Echo $ key. '=>'. $ value .'
';
}
Echo'
';
?> |
There is also a more advanced and common method
| The code is as follows: |
|
|
$ Shuiguo = array ('apple' => 10, 'Orange '=> 20, 'banner' => 30 );
While (list ($ changpin, $ jiage) = each ($ shuiguo ))
{
Echo "$ changpin => $ jiage ".'
';
}
?> |
I haven't paid much attention to it before. today I am doing it myself. it's good to know about new things, and I am still doing it myself.
The list () function can be used to break down an array into a series of values and name new variables. List-insensitive
Http://www.bKjia. c0m/phper/24/032 a7c95555c423729b071aef4afd3c4.htm
The two pieces of code output are the same.
Note that when using the each () function, the array records the current element. If you want to use the array twice in the same script. You need to use reset () to drop the current element and reset it to the beginning of the array.
| The code is 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 ","
";
}
?> |
In this way, you can still use the array $ price.
Bytes. Recently bought...