Problems after using a Foreach loop with two-dimensional arrays
Loop two times, the second loop is not displayed, but if the comment is dropped for the first time, the contents of the second loop can be displayed normally,
What friend knows the reason, please tell me, thank you very much!
PHP Code
$products 2 = Array ( ' name ' = ' apple ', ' quantity ' = = 6, ' unit price ' = + 12.2), Array (' name ' = ' banana ', ' quantity ' = = 2, ' unit price ' = > 15.1), Array (' name ' = ' watermelon ', ' quantity ' = = 3, ' unit price ' = 25.3) );//Loop one for ($i 1=0; $i 1
'; } Loop two /reset ($products 2); Even with the reset pointer, the following loop is still not shown, but if the loop is commented out, the loop two can be normal display, which friends know the reason for please tell me, thank you! For ($i 2=0; $i 2
'; }
Online and so on, thank you all first!
------Solution--------------------
A pointer to a subarray may also be reset.
For a problem with no pointers,
foreach, may move the pointer, the specific test bar
Each must be moving the pointer.
You can use all for, Foreach,each separately to see.
------Solution--------------------
Your first round of traversal is for $products2[$i 1], not $products2. In other words, the Reset () is $products2[$i 1], $products 2 pointers have never changed.
------Solution--------------------
PHP code
!--? PHP $products 2 = array (' name ' =--> ' Apple ', ' quantity ' = + 6, ' unit price ' and ' 12.2 ', Array (' name ' = ' = ' banana ', ' quantity ' = ' = 2 ', ' unit price ' = 15.1), array (' name ' = ' = ' watermelon ', ' quantity ') = 3, ' unit price ' = 25.3);//Loop one for ($i 1=0; $i 1
'; }//Loop Two for ($i 2=0, $i 2
'; }?>