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; a bit puzzled & nbsp; first: echo $ _ html Alas, I am 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
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.',';}