How to create Pyramid of asterisks in php
I need to create a pyramid using asterisks. I specify a value which becomes the base of the pyramid. I am facing a problem. Please see my code.
<?php
$n = $i = 5;
while ($i--)
echo str_repeat(' ', $i).str_repeat('*', $n - $i)."\n";
?>
PHP
- asked 7 years ago
- Priyanka Roy
2Answer
<html>
<head>
<title>create Pyramid of asterisks in php</title>
</head>
<body>
<pre>
<?php
$n = $i = 5;
while ($i--)
echo str_repeat(' ', $i).str_repeat('* ', $n - $i)."\n";
?>
</pre>
</body>
</html>
Text in a <pre> element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks.
- answered 7 years ago
- Community wiki
use This program within <center> </center>
tag
<center>
<?php
for($i=1;$i<=5;$i++){
for($j=1;$j<=$i;$j++){
echo "*";
}
echo "<br />";
}
?>
</center>
- answered 7 years ago
- Community wiki
Your Answer