Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. latihan8.html
  2.  
  3. <html>
  4. <body>
  5. Mengurutkan Array (Terbalik):<br><br>
  6. <form action="latihan8.php" method="post">
  7. Input 1 :<input type="text" name="input1"/><br>
  8. Input 2 :<input type="text" name="input2"/><br>
  9. Input 3 :<input type="text" name="input3"/><br>
  10. Input 4 :<input type="text" name="input4"/><br>
  11. Input 5 :<input type="text" name="input5"/><br><br>
  12. <input type="submit" value="Urutkan"/>
  13.  
  14. </form>
  15.  
  16. </body>
  17. </html>
  18.  
  19.  
  20. latihan8.php
  21.  
  22. <?php
  23.  
  24. function urutbalik()
  25. {
  26. $input1=$_POST["input1"];
  27. $input2=$_POST["input2"];
  28. $input3=$_POST["input3"];
  29. $input4=$_POST["input4"];
  30. $input5=$_POST["input5"];
  31. $inputs = array("$input1", "$input2", "$input3", "$input4", "$input5");
  32.  
  33.  
  34. if (is_numeric ($input1) && is_numeric ($input2) && is_numeric ($input3) && is_numeric ($input4) && is_numeric ($input5))
  35.  {
  36.  
  37. rsort($inputs);
  38. foreach ($inputs as $key => $val)
  39.     {
  40.     $key1=$key+1;
  41.     echo "$key1. $val<br>";
  42.     }
  43.  
  44.  }
  45. else
  46.     {
  47.  echo "Seluruh Input Harus berupa Angka";
  48.     }
  49. }
  50.  
  51.  
  52. ?>
  53.  
  54. <html>
  55. <body>
  56. Hasil yang Telah Diurutkan :<br><br>
  57. <?php
  58.  
  59.  
  60. urutbalik();
  61.  
  62.  
  63. ?>
  64. </body>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement