Home >Backend Development >PHP Tutorial >Examples of foreach and list loop statements in php_PHP tutorial
The article focuses on the usage of foreach loop and list loop statements. Well, let’s take a look at the implementation. I won’t go into too much detail. Students in need can refer to it.
I recently bought a PHP and MySQL web development program and saw array loop statements. It’s worth paying attention to, and hereby leave some writing for future reading.
Generally foreach is used more
The code is as follows
|
Copy code
|
||||||||||
{
echo '
There is a more advanced and common method |
The code is as follows | Copy code |
$shuiguo=array('apple'=>10,'orange'=>20,'banner'=>30);
While(list($changpin,$jiage)=each($shuiguo))
{
echo "$changpin=>$jiage".'
';
}
?>
I really didn’t pay much attention to it before, but I did it myself today, which was pretty good. I learned something new again, but I’m still too good at it, eh
The list() function can be used to decompose an array into a series of values, allowing new variables to be named. Those who don’t understand lists
The code is as follows | Copy code |
$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 way you can still use the array $price. http://www.bkjia.com/PHPjc/629245.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629245.htmlTechArticleThe article focuses on the usage of foreach loop and list loop statements. Well, let’s take a look at the implementation. I won’t go into too much detail. Students in need can refer to it. Recently bought... |