Home > Backend Development > PHP Tutorial > 唉,又犯晕了,帮帮忙解决办法

唉,又犯晕了,帮帮忙解决办法

WBOY
Release: 2016-06-13 13:27:34
Original
1003 people have browsed it

唉,又犯晕了,帮帮忙
$_POST['flags']=array(1,2,3,4,'a','b',"c");

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

}
echo $_html;

?>
有点纳闷
 第一个:echo $_html = $v.','; 得到值是1,2,3,4,a,b,c, 我明白
 第二个:echo $_html; 得到值应该和上面的一样,可以为什么得到的是c,

------解决方案--------------------
foreach 

你在循环内赋值,那么每一次这个值都给刷新 最后得到循环的最后一个值 所以就是c.
------解决方案--------------------

探讨

foreach

你在循环内赋值,那么每一次这个值都给刷新 最后得到循环的最后一个值 所以就是c.

------解决方案--------------------
$v.',';

它俩合起来赋值给html的,不是html合起$v.','
------解决方案--------------------
要想得到你希望的结果

PHP code
foreach(($_POST['flags']) as $v){
 echo $v.',';
 $_html .= $v.',';
} <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template