Do not want to correct the code I want why echo " ";
is not printed in my pyramid shape of *
?
$x = 7;
for($i=1;$i<=$x;$i++){
for($j=1; $j<=$x-$i; ++$j) {
echo " ";
}
for($k=1; $k<=$i; ++$k) {
echo "* ";
}
echo "<br>";
}
>Solution :
You can enclose your code in <pre> tags to display multiple spaces in the browser. We recommend using "\n" instead of <br>.
echo '<pre>';
$x = 7;
for($i=1;$i<=$x;$i++){
for($j=1; $j<=$x-$i; ++$j) {
echo " ";
}
for($k=1; $k<=$i; ++$k) {
echo "* ";
}
echo "\r\n";
}
echo '</pre>';
Alternatively, a special header can also be set with PHP.
header('Content-Type: text/plain');