Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
CREATE TABLE user_value (`user_name` varchar(4), `user_pass` varchar(3)) ;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php // Function to perform bubble sort on an array function bubble_Sort($my_array ) { // Loop until no swaps are made do { $swapped = false; // Flag to track if any elements were swapped // Iterate over the array for( $i = 0, $c = count( $my_array ) - 1; $i < $c; $i++ ) { // Compare adjacent elements if( $my_array[$i] > $my_array[$i + 1] ) { // Swap elements if they are in the wrong order list( $my_array[$i + 1], $my_array[$i] ) = array( $my_array[$i], $my_array[$i + 1] ); $swapped = true; // Set swapped flag to true } } } // Continue loop until no swaps are made while( $swapped ); return $my_array; // Return the sorted array } // Test array $test_array = array(3, 0, 2, 5, -1, 4, 1); echo "Original Array :\n"; echo implode(', ',$test_array ); // Display original array echo "\nSorted Array\n:"; echo implode(', ',bubble_Sort($test_array)). PHP_EOL; // Display sorted array ?>
Copy Clear