- str_pad: documentation ( source)
<?php
$renderPyramid = function ($height) {
$baseWidth = $height * 2 - 1;
for ($i = 1; $i <= $height; $i++) {
$spaces = str_pad('', $baseWidth - $i, ' ');
$dots = str_pad('', $i * 2 - 1, '.');
echo $spaces . $dots . PHP_EOL;
}
};
$renderPyramid(4);