Alas, I am dizzy again. help me solve the problem.

Source: Internet
Author: User
Alas, I am dizzy again. could you help me ;? Php $ _ POST ['flags'] = array (1, 2, 3, 4, 'A', 'B', & quot; c & quot ;); foreach ($ _ POST ['flags']) as $ v) {& nbsp; echo $ _ html = $ v. ',';} echo $ _ html ;? & Gt; I'm a bit confused. I'm dizzy again. could you 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
First: echo $ _ html = $ v. ','; the obtained values are 1, 2, 3, 4, a, B, and c. I understand
The second one: echo $ _ html; the obtained value should be the same as above. Why can we get c,

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

If you assign values in the loop, each time this value is refreshed, the last value of the loop is obtained. Therefore, it is c.
------ Solution --------------------
Discussion

Foreach

If you assign values in the loop, each time this value is refreshed, the last value of the loop is obtained. Therefore, it is c.

------ Solution --------------------
$ V .',';

They are assigned to html together, not $ v .','
------ Solution --------------------
To get the expected results
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.