Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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) {
- for ($i = 0; $i < count($array); $i++){
- //Checking if any index of array is string
- if (!is_string($array[$i])){
- // Creating loop
- for ($j = 0; $j < count($array); $j++) {
- // Creating loop that's sorting array $array
- for ($k = 0; $k < count($array) - 1; $k++) {
- // Checking if index $j is bigger than index $j + 1
- if ($array[$k] > $array[$k+1]) {
- // Swapping array pieces
- $temp = $array[$k];
- $array[$k] = $array[$k+1];
- $array[$k+1] = $temp;
- }
- }
- }
- //print_r($array);
- for ($index = 0; $index < count($array); $index++) {
- echo "<b>$array[$index]</b>";
- echo "<br />";
- }
- } else {
- echo "Pole tekstowe nie może zawierać żadnej litery!";
- break;
- }
- }
- }
- // Calling function
- bubbleSort($choosenNumbers);
- echo "<br /><a href='index.php'>Powrót</a>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment