Home  >  Article  >  Backend Development  >  求大神讲解

求大神讲解

WBOY
WBOYOriginal
2016-06-23 14:20:04898browse

在if判断在如何知道$flag何时是ture还是false,或者说怎么知道它是真还是假

   $arr=array('中','华','人','民','共','国',);

   for($flag=ture;current($arr);)){
     echo current($arr),'
';
       if($flag){
           next($arr);
           next($arr);
         $flag=flase;
}else{
 
     prev($arr);
     $flag=ture;}


回复讨论(解决方案)

arr=array('中','华','人','民','共','国',);for($flag=true;current($arr);){  echo key($arr), ':', current($arr), ' ', $flag ? 'true':'false', '<br/>';  if($flag){    next($arr);    next($arr);    $flag=false;  }else{    prev($arr);    $flag=true;  }}
0:中 true
2:人 false
1:华 true
3:民 false
2:人 true
4:共 false
3:民 true
5:国 false
4:共 true

Statement:
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