Home >php教程 >php手册 >不用api函数,实现数组的交换排序

不用api函数,实现数组的交换排序

WBOY
WBOYOriginal
2016-06-06 19:32:41995browse

不用api函数,实现数组的交换排序 无 $arr = array(900 , 20 , 16 , 50 , -2 , 10 , 3);$min = $max = 0;for ($j=0;$jcount($arr);$j++){for($i=0;$icount($arr)-1;$i++){if($arr[$i] $arr[$i+1]){$min = $arr[$i+1];$arr[$i+1] = $arr[$i];$arr[$i] = $min;}

不用api函数,实现数组的交换排序
	$arr = array(900 , 20 , 16 , 50 , -2 , 10 , 3);
	$min = $max = 0;
	
	for ($j=0;$j<count($arr);$j++){
		for($i=0;$i<count($arr)-1;$i++){
			if($arr[$i] > $arr[$i+1]){
				$min = $arr[$i+1];
				$arr[$i+1] = $arr[$i];
				$arr[$i] = $min;
			}
		}
		echo "当前数组为:";print_r($arr);echo "<br/>";
	}

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