Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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中使用for循环打印金字塔,就像给图像一样_Php - Fatal编程技术网

我只想在php中使用for循环打印金字塔,就像给图像一样

我只想在php中使用for循环打印金字塔,就像给图像一样,php,Php,我的代码是 <center> <?php for($i = 0; $i < 7 ; $i++) { for($j = 0; $j < $i; $j++) { echo "*"; } echo "<br/>"; } ?> <center> 但是我想要的是使用html标记的金字塔。您正在寻找这样的东西: <div class="text-

我的代码是

<center>
<?php

    for($i = 0; $i < 7 ; $i++) {

        for($j = 0; $j < $i; $j++) {
            echo "*";
        }
        echo "<br/>";
    }
?>
<center>


但是我想要的是使用html标记的金字塔。

您正在寻找这样的东西:

<div class="text-center"><!-- or however you choose to center this -->
<?php
$w = 7;
for ($n = 0; $n < $w; $n++) {
    echo str_repeat("-", $n) . "<br>";
}
?>
</div>


1)哪个图像?2) 问题是什么?给定的图像是?HTML标签已经被弃用了,我想它们已经不起作用了。我不能正确地提交我的问题…我的问题是我只想使用for循环php。没有在html中使用标记。很抱歉,如果你不能正确提交你的问题,你自然不会有正确的答案。我建议你阅读更多关于PHP-HTML解析、当前有效标记和PHP循环逻辑的内容,互联网上有很多教程。感谢每一位对我的问题做出贡献的人。但我仍然没有得到正确的答案。
<?php
   int k =0;
   for($i=1;$i<=20;$i++){
      for(a=1;a<=20;$a++){
         echo "  ";
      }   
      while(k!=(2*i-1){
         echo "* ";
         k++;
      }
      k=0;
      echo "\n";

   }
?>