PHP Online Compiler
Example: Print Star Pattern without using loop in PHP
C
C++
C#
Java
Python
PHP
main.php
STDIN
Run
<?php // Print Star Pattern without using loop in PHP // It's the number of rows $x = 10; // This will print the pattern starPattern($x); // It's the recursive function // to print the star pattern function starPattern($n, $i = 1, $r = 1) { if ((int)sqrt(pow(($i - (2 * $n - 1) * ($r - 1) - $n) , 2)) < $r) echo "*"; else echo " "; if (($i - (2 * $n - 1) * ($r - 1)) % (2 * $n - 1) == 0) { echo "\n"; $r++; } if ($i++ < $n * (2 * $n - 1)) starPattern($n, $i, $r); } ?>
Output
Clear
ADVERTISEMENTS