In this program, we are going to share a PHP Program to print mirror image of Swastika Pattern. If you are a beginner and want to start learning the PHP programming, then keep your close attention in this tutorial as I am going to share a PHP Program to print mirror image of Swastika Pattern.
Copy the below PHP program and execute it. At the end of this program, We have shared the output of this program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | <?php function revswastika($row, $col) { for ($i = 0; $i < $row; $i++) { for ($j = 0; $j < $col; $j++) { // for the upper half // of the Swastika if ($i < floor($row / 2)) { // checking if j < $col/2 if ($j < floor($col / 2)) { // the first quadrant will // have stars till half the // number of $rows if ($i == 0 && $i < floor($row / 2)) echo "*" . " "; // rest will have spaces else echo " " . " "; } // the middle line // of the swastika else if ($j == floor($col / 2)) echo "*"; else { // the second quadrant of the // upper half will have spaces if ($i < floor($row / 2) && $j < $col - 1) echo " " . " "; if ($j == $col - 1) // only the last $column // of the second quadrant // will have stars echo " " . "*"; } } // for the lower half of the Swastika // the middle horizontal line of the // Swastika will be at $row/2 else if ($i == floor($row / 2)) echo "*" . " "; else { // for stars in the third // quadrant and the middle // line of the lower // Swastika if ($j == floor($col / 2) || $j == 0) echo "*" . " "; else if ($i == $row - 1) { // the last $row's third // quadrant will have spaces // and the fourth will have // stars if ($j <= floor($col / 2) || $j == $col) echo " " . " "; else echo "*" . " "; } // rest of the remaining // portion will have spaces // all along else echo " " . " "; } } echo "\n"; } } // Driver code // same no. of $rows and $columns // to get the perfect mirror image // of swastika pattern. $row = 9; $col = 9; // function calling revswastika($row, $col); // This code is contributed by mits ?> |
Output:
1 2 3 4 5 6 7 8 9 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.