Daanniello Daanniello - 28 days ago 7
PHP Question

How to fix this PHP loop?


this is what i want.
123456
23456
3456
456
56
6


Hi, i have trouble with this loop.

<?php
for ($x = 7; $x >= 1; $x--) {
for ($y = 7; $y > $x; $y--) {
echo "&nbsp;&nbsp";
}
$s = 7;
while ($s < $x) {

$f++;
$s--;
}

for ($f=1; $f < 7; $f++) {
echo "$f";
}
echo "<br>";
}
?>


this is what i got. I want to get the $f work but it is ignoring it.

Dez Dez
Answer

You can make it simpler than you did.

for($x = 1; $x <= 6; $x++) {

    for($y = 1; $y <=6; $y++){ 
        if($x > $y)
            echo "&nbsp&nbsp;";
        else
            echo $y;
    }
    echo "<br>";
}

With x you control the lines and with y the columns. If the lines is greater than the column you print the spaces, and if not, the number.

Comments