Questions about using a Foreach loop with two-dimensional arrays

Source: Internet
Author: User
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 
    '; }?> 
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.