To print a right half pyramid pattern in PHP, you can use nested loops to control the number of rows and columns printed.
In this example,
$n
to represent the number of rows in the pyramid.<?php
$n = 5;
for ($i = 1; $i <= $n; $i++) {
$row = '';
for ($j = 1; $j <= $i; $j++) {
$row .= '*';
}
echo $row . "\n";
}
?>
* ** *** **** *****
In this tutorial, we learned How to print Right Half Pyramid Pattern in PHP language with well detailed examples.