Pyramid of stars in PHP

  • Sumo

Write a program to generate pyramid of stars.

This is the most commonly asked question to beginners. Though this seems to be very complex during my school days, but not.

Program to generate/draw pyramid of stars/asterisks in php

echo '<pre>';
$horizontal = 10;
$vertical = 10;
while ($vertical--)
echo str_repeat(' ', $vertical) . str_repeat('* ', $horizontal - $vertical) . "\n";
echo '</pre>';

Leave a Reply

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