php 求值2

假设 x = 2;
输出
4 5 8 9 10 11 16 17 18 19 20 21 22 23 32 33 34 35 ...

[4    5]        [8   9 10 11]    [16 17 18 19 20 21 22 23]    [32 33 34 35 ...
2*x             4*x                   8*x                                     16*x
阅读 2.3k
4 个回答
        define('X',2);

        define('MAX',10);

        for($i=1;$i<MAX;$i++){

            $count=pow(2,$i);

            $start=$count*X;

            for ($index=0; $index <$count ; $index++) { 

                echo ($start+$index)." ";

            }

        }

明天来我办公室一趟。

这么简单的PHP都不会,是不是翘课泡妞了?

$x=2;
$str='';
$end = 6;
for($i=2;$i<$end;$i++){
    $start = pow($x,$i);
    $str.=implode(',',range($start,$start+pow($x,$i-1)-1)).',';
}
echo rtrim($str,',');//4,5,8,9,10,11,16,17,18,19,20,21,22,23,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47
$x = 2;
for ($i = 1; $i <= $num; $i = $i * 2) {
    for ($j = 0; $j < $i; $j++) {
       echo ($i * $x + $j);
    }
}

// 期待更好的答案

推荐问题