HomePROGRAMMESTAR PATTERN PROGRAMMEInverted pyramid pattern

Inverted pyramid pattern

Inverted pyramid pattern
<?php
function invertedPyramid($n) {
    // Loop for rows
    for ($i = $n; $i >= 1; $i--) {
        // Print leading spaces
        for ($s = 0; $s < $n - $i; $s++) {
            echo " ";
        }
        // Print stars
        for ($j = 1; $j <= $i; $j++) {
            echo "* ";
        }
        echo "\n"; // new line
    }
}

// Call function
invertedPyramid(4);
?>

Share: 

No comments yet! You be the first to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *