Frezi2005

Untitled

Apr 10th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <html lang="pl">
  2. <head>
  3. <title>Bubble Sort</title>
  4. </head>
  5. <body>
  6.  
  7. <form action="sort.php" method="get">
  8. Liczby (odzielone przecinkiem): <input type='text' name='numbers'/>
  9. <button name="submitFormBtn">Dalej</button>
  10. </form>
  11.  
  12. </body>
  13. </html>
  14.  
  15. ////////////////sort.php/////////////////////
  16. <?php
  17.  
  18. // Putting values from input into variable
  19. $numbers = $_GET['numbers'];
  20. // Creating empty array
  21. $choosenNumbers = [];
  22. // Creating array values from text input
  23. $choosenNumbers = explode(",", $numbers);
  24.  
  25.  
  26. /*
  27. * Function sorting choosen array
  28. * Params $array
  29. */
  30. function bubbleSort($array) {
  31. // Creating loop
  32. for ($i = 0; $i < count($array); $i++) {
  33. // Creating loop that's sorting array $array
  34. for ($j = 0; $j < count($array) - 1; $j++) {
  35. // Checking if index $j is bigger than index $j + 1
  36. if ($array[$j] > $array[$j+1]) {
  37. // Swapping array pieces
  38. $temp = $array[$j];
  39. $array[$j] = $array[$j+1];
  40. $array[$j+1] = $temp;
  41. }
  42. }
  43. }
  44. print_r($array);
  45. }
  46.  
  47. // Calling function
  48. bubbleSort($choosenNumbers);
  49. echo "<br /><a href='index.php'>Powrót</a>";
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment