Frezi2005

Untitled

Apr 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2.  
  3. // Putting values from input into variable
  4. $numbers = $_GET['numbers'];
  5. // Creating empty array
  6. $choosenNumbers = [];
  7. // Creating array values from text input
  8. $choosenNumbers = explode(",", $numbers);
  9.  
  10. /*
  11. * Function sorting choosen array
  12. * Params $array
  13. */
  14. function bubbleSort($array) {
  15. for ($i = 0; $i < count($array); $i++){
  16. //Checking if any index of array is string
  17. if (!is_string($array[$i])){
  18. // Creating loop
  19. for ($j = 0; $j < count($array); $j++) {
  20. // Creating loop that's sorting array $array
  21. for ($k = 0; $k < count($array) - 1; $k++) {
  22. // Checking if index $j is bigger than index $j + 1
  23. if ($array[$k] > $array[$k+1]) {
  24. // Swapping array pieces
  25. $temp = $array[$k];
  26. $array[$k] = $array[$k+1];
  27. $array[$k+1] = $temp;
  28. }
  29. }
  30. }
  31. //print_r($array);
  32. for ($index = 0; $index < count($array); $index++) {
  33. echo "<b>$array[$index]</b>";
  34. echo "<br />";
  35. }
  36. } else {
  37. echo "Pole tekstowe nie może zawierać żadnej litery!";
  38. break;
  39. }
  40. }
  41. }
  42.  
  43. // Calling function
  44. bubbleSort($choosenNumbers);
  45. echo "<br /><a href='index.php'>Powrót</a>";
  46.  
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment