Home  >  Article  >  php教程  >  PHP简单的冒泡排序法(。•ˇ‸ˇ•。)

PHP简单的冒泡排序法(。•ˇ‸ˇ•。)

PHP中文网
PHP中文网Original
2016-05-22 18:24:59973browse

php代码

<?php
$b = [5,2,7,3,1,6,8,0];
// $b = [8,7,6,5,4,3,2,1,0];#直观地看出需要复循环几遍
$n = count($b);

for($s = 0;$s < $n;$s++){

	for($i = 0;$i $b[$i+1]) {	#升序排序

			$tmp = $b[$i+1];

			$b[$i+1] = $b[$i];

			$b[$i] = $tmp;
		}
	}
}
print_r($b);

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