tangga - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of tangga.php

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  <title>Tangga Warna</title>
  5.  <style>
  6.   body{
  7.    background-color: red;
  8.    font-family: cursive;
  9.   }
  10.   .tangga{
  11.    height: 10px;
  12.    width: 10px;
  13.    display: inline-block;
  14.    border: 1px solid black;
  15.   }
  16.   button{
  17.    background-color: black;
  18.    color: white;
  19.    border: 1px solid black;
  20.   }
  21.  </style>
  22. </head>
  23. <body>
  24.  <form method="post" action="">
  25.   <table>
  26. <tr>
  27.     <th>Tangga Berwarna</th>
  28.    </tr>
  29. <tr>
  30.     <td>Jumlah Anak Tangga</td>
  31.     <td><input type="text" name="jumlah"></td> 
  32.    </tr>
  33. <tr>
  34.     <td>Warna</td>
  35.     <td><input type="radio" name="warna" value="green">Hijau
  36.     <input type="radio" name="warna" value="purple">Ungu
  37.     <input type="radio" name="warna" value="yellow">Kuning
  38.     <input type="radio" name="warna" value="blue">Biru
  39.     <input type="radio" name="warna" value="grey">Abu</td>
  40.    </tr>
  41. <tr>
  42.     <td><button type="submit">Buat Tangga</button></td>
  43.    </tr>
  44. </table>
  45. </form>
  46. <?php 
  47.  
  48.   $jumlah = (int)$_POST['jumlah'];
  49.   $warna = $_POST['warna'];
  50.  
  51.   for ($i=1; $i <= $jumlah ; $i++) { 
  52.    for ($a=1; $a <= $i ; $a++) { 
  53.     echo <<<aw
  54.     <div class="tangga" style="background-color:$warna">
  55. </div>
  56. aw;;
  57.    }
  58.    echo "<br>";
  59.   }
  60.  
  61.   ?>
  62. </body>
  63. </html>
File Description
  • tangga
  • PHP Code
  • 29 Oct-2019
  • 1.24 Kb
You can Share it: