Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html lang="pl">
- <head>
- <title>Bubble Sort</title>
- </head>
- <body>
- <form action="sort.php" method="get">
- Liczby (odzielone przecinkiem): <input type='text' name='numbers'/>
- <button name="submitFormBtn">Dalej</button>
- </form>
- </body>
- </html>
- ////////////////sort.php/////////////////////
- <?php
- // Putting values from input into variable
- $numbers = $_GET['numbers'];
- // Creating empty array
- $choosenNumbers = [];
- // Creating array values from text input
- $choosenNumbers = explode(",", $numbers);
- /*
- * Function sorting choosen array
- * Params $array
- */
- function bubbleSort($array) {
- // Creating loop
- for ($i = 0; $i < count($array); $i++) {
- // Creating loop that's sorting array $array
- for ($j = 0; $j < count($array) - 1; $j++) {
- // Checking if index $j is bigger than index $j + 1
- if ($array[$j] > $array[$j+1]) {
- // Swapping array pieces
- $temp = $array[$j];
- $array[$j] = $array[$j+1];
- $array[$j+1] = $temp;
- }
- }
- }
- print_r($array);
- }
- // Calling function
- bubbleSort($choosenNumbers);
- echo "<br /><a href='index.php'>Powrót</a>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment