Php bubble sorting algorithm implementation code
- // Bubble sorting function
- // Reference this function to avoid memory consumption
- // Finishing: bbs.it-home.org
- Function & bubble (& $ arr ){
- $ Count = count ($ arr );
- If ($ count> 1 ){
- For ($ I = 0; $ I <$ count; $ I ++ ){
- For ($ j = $ count-1; $ j >=$ I; $ j --){
- If ($ arr [$ j-1]> $ arr [$ j]) {
- $ Temp = $ arr [$ j-1];
- $ Arr [$ j-1] = $ arr [$ j];
- $ Arr [$ j] = $ temp;
- }
- }
- }
- }
- Return $ arr;
- }
-
- // Output array (for viewing on the webpage)
- Function printArr (& $ arr ){
- Echo"
"; - print_r($arr);
- echo "
";
- }
-
- // Start the test
- // Randomly assign ten values to the array
- For ($ I = 0; $ I <10; $ I ++ ){
- $ TestArr [] = rand (10,100 );
- }
-
- PrintArr (bubble ($ testArr ));
- ?>
>>> Articles you may be interested in: php examples of practical and fast sorting algorithms PHP implementation of various sorting algorithms small example of php bubble sorting php simple example of bubble sorting PHP implementation of two-dimensional array sorting user-defined function php selection of sorting implementation code php bubble sorting implementation code php insert sorting implementation code php quick sort) function php for fast sorting function php for bubble sorting exchange sorting method php for bubble sorting (bubble sort) php bubble sorting algorithm example php bubble sorting and quick sorting example php two-dimensional array sorting method php multi-dimensional array sorting |