If you use foreach to loop the two-dimensional array, the second loop will not be displayed, but if you comment out the first loop, the content of the second loop will be displayed normally, which of your friends knows the reason? thank you very much! PHPcode $ products2 = array ('name' = & gt; 'apple', 'number' = & gt; 6. problems after using foreach to loop two-dimensional arrays
The second loop will not be displayed in the second loop. However, if you comment out the first loop, the content of the second loop will be displayed normally,
Which of your friends knows the reason? thank you very much!
PHP code
$ Products2 = array ('name' => 'apple', 'qty '=> 6, 'unit price' => 12.2 ), array ('name' => 'banana ', 'quantity' => 2, 'unit price' => 15.1), array ('name' => 'watermelon ', 'qty '=> 3, 'unit price' => 25.3); // Loop 1 for ($ i1 = 0; $ i1
';} // Loop 2 // reset ($ products2); even if a reset pointer is added, the following loop cannot be displayed, but if you comment out the loop, loop 2 is displayed normally. if you know the reason, please let me know. thank you! For ($ i2 = 0; $ i2
';}
Online, etc. thank you!
------ Solution --------------------
This may also require sub-array pointers to be reset.
For has no pointer problem,
Foreach, the pointer may be moved. For more information, see test.
Each must be a mobile pointer.
You can use for, foreach, and each to test them separately.
------ Solution --------------------
Your first round of traversal is for $ products2 [$ i1] instead of $ products2. In other words, the reset () is $ products2 [$ i1], and the $ products2 pointer has never changed.
------ Solution --------------------
PHP code
'Apple', 'qty '=> 6, 'unit price' => 12.2), array ('name' => 'ban', 'qty' => 2, 'Unit price' => 15.1), array ('name' => 'watermelon ', 'quantity' => 3, 'unit price' => 25.3 )); // Loop 1 for ($ i1 = 0; $ i1
';} // Loop 2 for ($ i2 = 0; $ i2
';}?>