PHP Online Compiler
Example: Butterfly Pattern in PHP of Numbers
C
C++
C#
Java
Python
PHP
main.php
STDIN
Run
<?php // Butterfly Pattern in PHP of Numbers // Size of the butterfly pattern $h = 7; echo "This the butterfly pattern:\n\n"; // This will print the butterfly pattern butterflyPattern($h); // It's the function to // print the butterfly pattern function butterflyPattern($h) { for($r = 1; $r <= $h - 1; $r++) { echo "\t"; for($d = 1; $d <= $r; $d++) echo $d . " "; for($s = 1; $s <= 2 * ($h - $r); $s++) echo " "; for($d = $r; $d >= 1; $d--) echo $d . " "; echo "\n"; } for($r = $h; $r >= 1; $r--) { echo "\t"; for($d = 1; $d <= $r; $d++) echo $d . " "; for($s = 1; $s <= 2 * ($h - $r); $s++) echo " "; for($d = $r; $d >= 1; $d--) echo $d . " "; echo "\n"; } } ?>
Output
Clear
ADVERTISEMENTS