Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Dubble For循环_Php_Loops_For Loop - Fatal编程技术网

PHP Dubble For循环

PHP Dubble For循环,php,loops,for-loop,Php,Loops,For Loop,我需要在php中做一个循环,在循环中说1*9=9 2*9=18,1*8=8,1*7=7等等,结果如下: 1*7 = 7 2*7 = 14 3*7 = 21 1*8 = 8 2*8 = 16 3*8 = 24 1*9 = 9 2*9 = 18 3*9 = 27 我需要使用一个嵌套循环,因为我尝试了一些东西,但我不能让它在这里工作。但在大多数情况下,我并不真正理解嵌套循环的作用和用途。希望你能帮助我,谢谢 for ($tafel7 = 0; $tafel7 <= 9; $tafel7

我需要在php中做一个循环,在循环中说1*9=9 2*9=18,1*8=8,1*7=7等等,结果如下:

1*7 = 7
2*7 = 14
3*7 = 21
1*8 = 8
2*8 = 16
3*8 = 24
1*9 = 9
2*9 = 18
3*9 = 27
我需要使用一个嵌套循环,因为我尝试了一些东西,但我不能让它在这里工作。但在大多数情况下,我并不真正理解嵌套循环的作用和用途。希望你能帮助我,谢谢

    for ($tafel7 = 0; $tafel7 <= 9; $tafel7++) {
        for($tafel7 = 0; $tafel7 <= 9; $tafel7++){
            for($tafel7 = 0; $tafel7 <= 9; $tafel7++){

            $antwoord9 = $tafel7 * 9;
            echo "$tafel7 x 8 = $antwoord9 <br>";

            $antwoord8 = $tafel7 * 8;
            echo "$tafel7 x 8 = $antwoord8 <br>";

            $antwoord7 = $tafel7 * 7;
            echo "$tafel7 x 7 = $antwoord7 <br>";


            };
        };
    };

对于($tafel7=0;$tafel7在本例中,我必须循环一个时间表,例如7、8和9“tafel”,另一个循环,循环每个时间表“$hoeveel”的运行次数。这可以很容易地更改为更多的时间表或您希望运行的次数,您也只需要在循环中导出一次值。希望有帮助

for ($tafel = 7; $tafel <= 9; $tafel++) {
    for ($hoeveel = 1; $hoeveel <= 3; $hoeveel++) {
        $antwoord = $tafel * $hoeveel;
        echo "$tafel x $hoeveel = $antwoord <br>";
    }
}

对于($tafel=7;$tafel您需要循环两个变量,(1)左操作数和(2)右操作数


for($right=7;$right您的问题不太清楚,但如果您只想得到确切的结果,下面是代码:

for($i = 7; $i <= 9; $i++){
    for($j = 1; $j <= 3; $j++){
        $result = $i * $j;
        echo $j." * ".$i." = ".$result."<br>";
    }
}

用于($i=7;$i在循环中尝试不同的变量名明确您想要实现的目标。您只需提供输入参数。这将很容易理解jy het reg gekom,al was ek die eerste ou wat GEHET。我使用了7、8和9倍表,并且每个表中只有前3个可以始终更改值,您使用的是same变量和许多嵌套循环。如果您编辑解释此代码发生了什么的答案,我会更新此答案,因为OP目前不知道他正在使用嵌套for循环做什么。很抱歉,将其更改为提供更多解释
for($i = 1; $i <= 9; $i++){
    for($j = 1; $j <= 10; $j++){
        $result = $i * $j;
        echo $i." * ".$j." = ".$result."<br>";
    }
}