Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.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 每三次打印一次_Php - Fatal编程技术网

Php 每三次打印一次

Php 每三次打印一次,php,Php,等等。我尝试了很多方法来获得这个,这是我最接近的,也是我最接近的。此打印内容位于此处(难以打印)。我怎样才能完成每三次的技巧 $t = 3; * $t = 6; ** $t = 9; *** %是模运算符,它返回除法的余数。如果结果为0,则进行除法时没有余数 %是模运算符,它返回除法的余数。如果结果为0,则进行除法时没有余数。在大多数语言中都可以使用模运算符,即除法运算的余数 如果(iterationNumber%3==0),这是第三次。您可以在大多数语言中使用模运算符,即除法运算的

等等。我尝试了很多方法来获得这个,这是我最接近的,也是我最接近的。此打印内容位于此处(难以打印)。我怎样才能完成每三次的技巧

$t = 3;

*

$t = 6;

**

$t = 9;

***
%
是模运算符,它返回除法的余数。如果结果为0,则进行除法时没有余数


%
是模运算符,它返回除法的余数。如果结果为0,则进行除法时没有余数。

在大多数语言中都可以使用模运算符,即除法运算的余数


如果(iterationNumber%3==0),这是第三次。

您可以在大多数语言中使用模运算符,即除法运算的剩余部分


如果(iterationNumber%3==0),这是第三次。

/
为您提供商。相反,您需要使用
%
运算符,检查
%
运算的结果是否为0,然后打印值

if($something % 3 == 0)
{
  //do something
}

/
给出了商。相反,您需要使用
%
运算符,检查
%
运算的结果是否为0,然后打印值

if($something % 3 == 0)
{
  //do something
}

我不太清楚您想做什么,但我怀疑您缺少的是模运算符,
%

在PHP中,
x%y
计算x除以y得到的余数。因此,如果您正在计算某个值,并且希望每三个值运行一段代码,您可以执行以下操作:


如果(0=$count%3){
//对每三个项目执行的操作
} 

有关更多信息,请参阅上的PHP手册

此外,我认为您可能还需要一个for循环,以便打印出正确的*s数

<?php

$ohhai = 1;
$times = 1;   // This is variable that keeps track of how many times * needs to printed. It's fairly straight forward to understand, why this variable is needed.

while ($ohhai != 102)
{
    if ($t % 3 == 0)
    {
        for ( $counter = 0; $counter < $times; $counter++)
        {
            echo "*";
        }
        $times ++;
        echo("<br />");
    }
    $ohhai++;
}

?>

我不太清楚您想做什么,但我怀疑您缺少的是模运算符,
%

在PHP中,
x%y
计算x除以y得到的余数。因此,如果您正在计算某个值,并且希望每三个值运行一段代码,您可以执行以下操作:


如果(0=$count%3){
//对每三个项目执行的操作
} 

有关更多信息,请参阅上的PHP手册

此外,我认为您可能还需要一个for循环,以便打印出正确的*s数

<?php

$ohhai = 1;
$times = 1;   // This is variable that keeps track of how many times * needs to printed. It's fairly straight forward to understand, why this variable is needed.

while ($ohhai != 102)
{
    if ($t % 3 == 0)
    {
        for ( $counter = 0; $counter < $times; $counter++)
        {
            echo "*";
        }
        $times ++;
        echo("<br />");
    }
    $ohhai++;
}

?>

使用模运算符

例如:

  • 10%2=0
    因为2除以10没有余数
  • 10%3=1
    因为3将10除以1的余数
  • 因此,对于您的注释代码,您的脚本如下所示:

    <?php
    
    $ohhai = 1;
    
    while ($ohhai != 102)
    {
        for($t = 1; $t < $ohhai; $t++)
        {
            //if ($t % 3 == 0)
            //{
                $e = $t / 3;
                if (is_int($e))
                {
                    echo "*";
    
                }
            //}
        }
    
        echo("<br />");
        $ohhai++;
    }
    
    ?>
    
    <?php
    
    $ohhai = 1;
    
    while ($ohhai != 102)
    {
    
      // we only want to print on multiples of 3
      if( 0 == $ohhai % 3 ) {
    
    
       for($t = 1; $t <= $ohhai; $t++){
           echo "*";
       }
    
       echo("<br />\n");
      }
    $ohhai++;
    }
    

    使用模运算符

    例如:

  • 10%2=0
    因为2除以10没有余数
  • 10%3=1
    因为3将10除以1的余数
  • 因此,对于您的注释代码,您的脚本如下所示:

    <?php
    
    $ohhai = 1;
    
    while ($ohhai != 102)
    {
        for($t = 1; $t < $ohhai; $t++)
        {
            //if ($t % 3 == 0)
            //{
                $e = $t / 3;
                if (is_int($e))
                {
                    echo "*";
    
                }
            //}
        }
    
        echo("<br />");
        $ohhai++;
    }
    
    ?>
    
    <?php
    
    $ohhai = 1;
    
    while ($ohhai != 102)
    {
    
      // we only want to print on multiples of 3
      if( 0 == $ohhai % 3 ) {
    
    
       for($t = 1; $t <= $ohhai; $t++){
           echo "*";
       }
    
       echo("<br />\n");
      }
    $ohhai++;
    }
    
    
    
    $total=102;
    对于($i=1;$i
    $total=102;
    

    对于($i=1;$i这是注释掉的代码。如果未注释,它看起来像这样:这是注释掉的代码。如果未注释,它看起来像这样:这是注释掉的代码。如果未注释,它看起来像这样:这是注释掉的代码。如果未注释,它看起来像这样:这是注释掉的代码。如果未注释,我t看起来是这样的:@Imnotanerd-检查一下。我想这就是你需要的。$t是一个错误吗?你的意思是$times吗?当我注意到时,你发布了评论。更正了。谢谢。我将$times++;移到if循环之外,并在$counter<$times之后放置了一个/3,现在它工作了!谢谢你的帮助!:d这是注释掉的代码。用它取消注释ed,它看起来是这样的:@Imnotanerd-检查一下。我想这就是你需要的。$t是错误吗?你是指$times吗?当我注意到时,你发布了评论。更正。谢谢。我将$times++;移到if循环之外,并在$counter<$times之后放置了一个/3,现在它工作了!谢谢你的帮助!:d这是注释掉的代码。有了它,unco它看起来是这样的:这是注释掉的代码。如果它没有注释,它看起来是这样的:你能显示打开的确切代码吗?你能显示打开的确切代码吗