Categories
PHP

Half Triangle Star Pattern Program in PHP

*
* *
* * *
* * * *
* * * * *
*
**
***
****
*****

To print the above half triangle star pattern, first we should know the logic to print the pattern.
We can consider the pattern in the form of matrix of 5×5.

Now we will use nested for loop. First loop for rows and second for columns.

The final php code for above star pattern will be as below.

// PHP Code for pattern
for ($i = 1; $i <= 5; $i++) {

    for ($j = 1; $j <= $i; $j++) {
    
        echo "* ";
    }
    
    echo "<br>"; // for new line
}

You can follow the below video as well.

Leave a Reply

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