Generally foreach is used more
Copy the code The code is as follows:
$price=array('apple'=>10,'orange'=>20,'banner'= >30);
foreach($price as $key=>$value)
{
echo $key.'=>'.$value.'
';
}
echo '
20,'banner'=>30);
while(list($changpin,$jiage)=each($shuiguo))
{
I really didn’t pay much attention to it before, but today I did it by myself, it’s not bad, I learned new things again, but I’m still too good at it, ehlist() function Can be used to decompose an array into a series of values, allowing new variables to be named. If you don’t understand lists, click here The output of the two pieces of code is the same.
It should be noted that when using the each() function, the array will record the current element. If you want to use the array twice in the same script. You need to use reset() to reset the current element to the beginning of the array.
Copy the code
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","
"; }
This way you can still use the array $price.
There are some in the book. As a novice, I do it myself, type it to see the effect, understand it, and write a post in case I forget to read it later. It is relatively superficial and the language is not well expressed, which is ridiculous.
Copy the code
The code is as follows:
/*
*Loop statement study notes in PHP
Execute this loop body repeatedly; } *2.do-while loop*3.for loop*There are two types of loops depending on the loop conditions
*One: counting 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 break out of loops.
continue;//can only be used in the loop body to exit this loop. exit;
return;
*Try not to exceed three levels of writing loops.
*Try not to exceed five levels of loop flow control statements.
*/
$num=0;
while($num<100){
echo "This is the result of executing the {$num}th output
";
$num++;
}
//
echo '
' .$i.' | ';