PHP program to print alphabet pattern K

In this article write a PHP program to print alphabet pattern K. This Program first takes the numbers of rows and then prints pattern using nested for loops.

PHP program to print alphabet pattern K

<?php
echo "<pre>";
$j = 7;
$i = 0;
for ($row = 0; $row <= 10; $row++) { 
    for ($col = 0; $col <= 10; $col++) {
        if ($col == 1 OR (($row == $col + 3) AND $col != 0)) {
            echo "*";
        } else if ($row == $i AND $col == $j) {
            echo "*";
            $i = $i + 1;
            $j = $j - 1;
        } else {
            echo "&nbsp;";
        }
    }
    echo "<br/>";
}
echo "</pre>";
?>

Output:

alphabet pattern K

Leave A Reply

Your email address will not be published.