Home > Backend Development > PHP Tutorial > php bubble sort method

php bubble sort method

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-09-01 00:20:17
Original
907 people have browsed it

php bubble sort method
Why the last one can’t be ranked

php bubble sort method

Reply content:

php bubble sort method
Why the last one can’t be ranked

php bubble sort method

You should let $i=0 in the first for

================================
I guess you made a mistake and copied $i into $j.

j = 0;
j = 1;
j = 2;
//Oops, I accidentally copied it wrong and only executed it 3 times
exit;

The number of loops is wrong, $j
The second level loop should be -$i, not minus $j

<code>$arr = array(21,7,5,23,2);
var_dump($arr);
$long = count($arr);
for($i=0;$i<$long;$i++){
    for($j=0;$j<$long-$i-1;$j++){
        if($arr[$j]>$arr[$j+1]){
            $x = $arr[$j+1];
            $arr[$j+1]=$arr[$j];
            $arr[$j]=$x;
        }
    }
}
var_dump($arr);</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template