Copy code The code is as follows:
$arr = array(345,4,17,6,52 ,16,58,69,32,8,234);
$n = count($arr);
for($i=1;$i<$n;$i++){
//where Why $n-1 is because the array is calculated from 0
//The next is the first inner loop
for($j=$n-1;$j>=$i;$j --)
{
//If $arr[10]<$arr[9];
//temp = $arr[9];
if($arr[$j] <$arr[$j-1]){
//$temp put the small values together for now
$temp = $arr[$j-1];
//Start at this time The positions are about to be swapped
$arr[$j-1] = $arr[$j];
//$arr[9] = the value of $arr[10]
$arr[$j] = $temp;
//The value of $arry[10] is equal to the value of $arr[9]
//At this time, the positions will start to be exchanged
}
}
}
?>
http://www.bkjia.com/PHPjc/323999.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323999.htmlTechArticleCopy the code as follows: ?php $arr = array(345,4,17,6,52,16, 58,69,32,8,234); $n = count($arr); for($i=1;$i$n;$i++){ //Why $n-1 is because the array starts from 0 Calculated...
Statement: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