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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:32:41
Original
1018 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
Latest Issues
用phpstorm
From 1970-01-01 08:00:00
0
0
0
angular.js - angularJS ng-style用法
From 1970-01-01 08:00:00
0
0
0
Why did the teacher’s submission fail?
From 1970-01-01 08:00:00
0
0
0
composer installation failed
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template