const printNumberStarMatrix = function (row, col) { for (let i = 1; i <= row; ++i) { let strToPrint = ""; for (let j = col - i; j >= 1; --j) { strToPrint = j + strToPrint; } while (strToPrint.length < col) { strToPrint += "*"; } console.log(strToPrint); } }
<?php $printNumberStarMatrix = function ($row, $col) { for ($i = 1; $i <= $row; ++$i) { $strToPrint = ""; for ($j = $col - $i; $j >= 1; --$j) { $strToPrint = $j + $strToPrint; } } while ($strToPrint < $col) { $strToPrint += "*"; } echo $strToPrint; }; $printNumberStarMatrix(5, 6); ?>
while (strToPrint.length < col)
while ($strToPrint < $col)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)