Introduction: This is a detailed page for PHP sorting. It introduces the related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 339370 'rolling = 'no'>
The last section of the TCP/IP test ended, and my sophomore life ended relentlessly. In the morning, let's see if our friends are still asleep and don't know what to do. Then they began to wander. We can see that a brother writes data in Bubble sorting.AlgorithmSorting the arrays in PHP makes me laugh. why are so many sorting functions in PHP still writing this ?! Later I thought about it. I was wrong. programming is not just a mechanical movement, but a set of multiple ways of thinking. The purpose of practicing algorithms is to expand my own thinking.
I also tried to write ......
<? PHP
$ Array = array );
$ Num = count ($ array );
For ($ I = 0; $ I <$ num-1; $ I ++ ){
For ($ J = $ I + 1; $ j <$ num; $ J ++ ){
If ($ array [$ J]> $ array [$ I]) {// here, the value of the array is exchanged.
$ Temp = $ array [$ I];
$ Array [$ I] = $ array [$ J];
$ Array [$ J] = $ temp;
}
}
}
Print_r ($ array );
?>
This is the Bubble sorting algorithm, and the result is still acceptable:
---------- PHP debug ----------
Array
(
[0] => 86
[1] => 56
[2] => 41
[3] => 36
[4] => 15
[5] => 10
[6] => 9
[7] => 8
[8] => 5
[9] => 4
[10] => 3
[11] => 2
)
Output completed (0 seconds)-normal termination
With the little joy of success, I wrote another one, and the problem came out --
<? PHP
$ Array = array );
$ Num = count ($ array );
For ($ I = 0; $ I <$ num-1; $ I ++ ){
For ($ J = $ I + 1; $ j <$ num; $ J ++ ){
If ($ array [$ J]> $ array [$ I]) {// here is the exchange key value
$ Temp = $ I;
$ I = $ J;
$ J = $ temp;
}
}
}
Print_r ($ array );
?>
The results are terrible ......
---------- PHP debug ----------
Array
(
[0] => 10
[1] => 5
[2] => 36
[3] => 86
[4] => 2
[5] => 56
[6] => 9
[7] => 15
[8] => 8
[9] => 4
[10] => 3
[11] => 41
)
Output completed (0 seconds)-normal termination
I didn't change either. Why ?? Why ???
I forgot to give my opinion when I pass ......
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/339370.html pageno: 8.