PHP完全自学手册(珍藏版) 中文pdf扫描版下载
- <?php
- /**
- * Created by PhpStorm.
- * User: miyingshuai
- * Date: 16/7/26
- * Time: 下午9:03
- */
- //顺序
- $arr = [1,3,4,5,6,7,8,12,31];
- $len = count($arr);
- for($i=1;$i<$len;$i++) {
- for($k=0;$k<$len-$i;$k++) {
- if($arr[$k]>$arr[$k+1]) {
- $tmp = $arr[$k+1];
- $arr[$k] = $arr[$k+1];
- $arr[$k+1] = $tmp;
- }
- }
- }
- print_r($arr);
- //倒序
- $arr = [1,3,4,5,6,7,8,12,31,8888,8888,1];
- $len = count($arr);
- for($i=0;$i<$len-1;$i++) {
- $p = $i;
- for($j=$i+1;$j<$len;$j++) {
- if($arr[$p]<$arr[$j]) {
- $p = $j;
- }
- }
- if($p!=$j) {
- $tmp = $arr[$p];
- $arr[$p] = $arr[$i];
- $arr[$i] = $tmp;
- }
- }
- print_r($arr);