To create a pyramid we need 3 repetitions for example as follows:
<?php
//PYRAMID TOP
for ($i = 0; $i < 5; $i++) {
for ($j = 5; $j > $i; $j--) {
echo ' ';
}
for ($k = 0; $k <= $i; $k++) {
echo '*';
}
echo '<br/>';
}
//PYRAMID BOTOM
echo "<br/><br/>";
for ($i = 1; $i <= 5; $i++) {
for ($j = 6; $j > $i; $j--) {
echo '*';
}
for ($k = 2; $k <= $i; $k++) {
echo '';
}
echo '<br/>';
}
?>
for ($ i); // repetition i to make the number of rows repetition of 0 to no more than 5, i ++ grow 0-4, echo '<br/>', // to act line
for ($ j); // repetitions to create a column j j 5 worth no more than i (0), 5-0 j-- reduced, echo '& nbsp' // to display a blank character
for ($ k); // repetitions k to fill column 0 as i no more and grow, echo '*'; // to produce a character *
The result:
If you have any questions please comment.
Do not forget to like and share.
learn Programming in fajaryusuf.com . :)
Comments