Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-06 19:32:41
Original
972 people have browsed it

不用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/>";
	}

Copy after login
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!