Correctly apply the PHPforeach loop. Htmlbody? Php $ arrarray (one, two, three); foreach ($ arras $ value) {echoValue:. $ value.br ;}? In this PHPforeach loop example, bodyhtml creates the $ arr array
- < Html>
- < Body>
- <? Php
- $ Arr = array ("one", "two", "three ");
- Foreach ($ arr as $ value)
- {
- Echo "Value:". $ value ."< Br />";
- }
- ?>
- </Body>
- </Html>
In this PHP foreach loop example, we create a $ arr array with the element values "one", "two", "three ", then, a foreach loop is used to output the value of its array. The values in the array are saved to the variable value through "as", so that the value stores all elements of the array arr.
Here, we are targeting an array with automatic indexing. what if it is an associated array? See the following situation:
- $sounds=array(”cow”=>”moo”,”dog”
=>”woof”,”pig”=>”oink”,”duck”=>
”quack”);
- foreach($sounds as $animal=>$sound)
- {
- Print “And of that farm he had a
{$animal}”;
- }
Note: Through the PHP foreach loop, we assign the $ sounds key of the array to the variable $ animal and assign the value of the array to $ sound, in this way, we can easily access each "key-value pair" in the array.
The http://www.bkjia.com/PHPjc/446070.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446070.htmlTechArticlehtml body? Php $ arr = array (one, two, three); foreach ($ arras $ value) {echoValue:. $ value. br /;}? /Body/html in This PHP foreach loop example, we created the $ arr array, in...