Posts

Print the Patterns

Image
<?php // Php code to demonstrate // star pattern // Function to demonstrate // printing pattern function pypart($n) { // Outer loop to handle number // of rows in this case for ($i = 0; $i < $n; $i++) { // inner loop to handle // number of columns // values changing acc. // to outer loop for($j = 0; $j <= $i; $j++ ) { // Printing stars echo "* "; } // ending line after // each row echo "\n"; } } // Driver Code $n = 5; pypart($n); ?> <?php // PHP code to demonstrate // star pattern // Function to demonstrate // printing pattern function pypart2($n) { for ($i = 1; $i <= $n; $i++) { for ($j = 1; $j <= $n; $j++) { if($j<=($n-$i)){ echo " "." "; }else { echo "* "; } } echo PHP_EOL; } } // Driver Code $n = 5; pypart2($n); ?> <?php // PHP code to demonstrate // star pattern // Function to demonstrate // printing pattern function triangle($n) { // number of spaces $k = 2 * $n - 2; // outer loop to h...

Print multiplication table of a number

 <!DOCTYPE html> <html> <body> <center> <h1 style="color: green;"> GeeksforGeeks </h1> <h3> Program to print multiplication<br> table of any number in PHP </h3> <form method="POST"> Enter a number: <input type="text" name="number"> <input type="Submit" value="Get Multiplication Table"> </form> </center> </body> </html> <?php if($_POST) { $num = $_POST["number"]; echo nl2br("<p style='text-align: center;'> Multiplication Table of $num: </p> "); for ($i = 1; $i <= 10; $i++) { echo ("<p style='text-align: center;'>$num" . " X " . "$i" . " = " . $num * $i . "</p> "); } } ?>

Check a year whether it is leap year or not

  <?php $year = 2019; if ($year % 400 == 0) {    echo $year." is a leap year."; } elseif ($year % 100 == 0) {    echo $year." is not a leap year."; } elseif ($year % 4 == 0) {    echo $year." is a leap year."; } else {    echo $year." is not a leap year."; } ?>

Check a number whether it is even or odd

  <?php // PHP code to check whether the number  // is Even or Odd in Normal way function check( $number ){      if ( $number % 2 == 0){          echo "Even" ;       }      else {          echo "Odd" ;      } }     // Driver Code $number = 39; check( $number ) ?>