简体   繁体   中英

Can i use divide in loop for PHP?

Can i use divide in loop for PHP ?

I write code like that but not work.

<?PHP
    for ($k=100;$k>2;$k/2)
        {echo $k;}
?>

That should be $k = $k / 2 , or $k /= 2 .

As pointed out in the comments, you could also use a bit shift operation $k >>= 1 .

Try with:

for ($k=100;$k>2;$k = $k/2) {
    echo $k;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM