Home  >  Article  >  Backend Development  >  为啥循环不出来这个数呢

为啥循环不出来这个数呢

WBOY
WBOYOriginal
2016-06-23 13:39:26763browse

$no=0;
            while($bqrf=$empire->fetch($cx)) {
            if($no%1==0){
                $num=1;
             }elseif($no%2==0){
                $num=2;
             }elseif($no%3==0){
                $num=3;
             }
           $no++;
           echo $no;//有值,能循环出来1,2,3,4...................
           echo $num;输出的全是1
上面的$num不能按要求输出,不知为啥


回复讨论(解决方案)

因为全进入 if($no%1==0){ } 这个if了。

 数学啊数学

任何正整数求余1都是0,

 if($no%1==0){                $num=1;

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