Oh, I'm dizzy again, help me out.

Source: Internet
Author: User
Oh, I'm dizzy again, help me.
$_post[' Flags ']=array (1,2,3,4, ' A ', ' B ', ' C ');

foreach (($_post[' flags ')) as $v) {
echo $_html = $v. ', ';

}
Echo $_html;

?>
A little puzzled.
The first one: echo $_html = $v. ', '; Get the value is 1,2,3,4,a,b,c, I understand
The second one: Echo $_html; Get the value should be the same as above, why you get C,

------Solution--------------------
Foreach

You assign a value in the loop, so every time this value is refreshed and finally gets the last value of the loop, so that's C.
------Solution--------------------
Explore

Foreach

You assign a value in the loop, so every time this value is refreshed and finally gets the last value of the loop, so that's C.

------Solution--------------------
$v. ', ';

Together, they are assigned to HTML, not HTML $v. ', '
------Solution--------------------
To get the results you want.
Change
PHP Code
foreach (($_post[' flags ')) as $v) {echo $v. ', '; $_html. = $v. ', ';}
  • 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.