排序
<?php
//插入排序
function insertSort($arr){
//检测数组
$len = count($arr);
if($len < 2){
return $arr;
}
$sign = 1;
$sortArr = array();
foreach($arr as $key=>$value){
if(1 === $sign){
$sign = 2;
$sortArr[$key] = $value;
}else{
$tmpArr = array();
$end = count($sortArr);
$j = 0;
foreach($sortArr as $k=>$v){
$j++;
if($value < $v){
$tmpArr[$key] = $value;
$tmpArr[$k] = $v;
}else{
$tmpArr[$k] = $v;
}
}
if($j == $end){
$tmpArr[$key] = $value;
}
$sortArr = $tmpArr;
}
}
return $sortArr;
}
$arr = array('a'=>1, 'b'=>9, 'c'=>5, 'd'=>12, 'e'=>2, 'f'=>6);
var_dump($arr);
var_dump(insertSort($arr));