<?php
header("content-type:text/html;charset=utf-8");
echo "<pre>";
$arr = array(1, 1, 5, 6, 3, 2, 9, 4, 5, 9, 4, 2, 7, 7);
echo "排序前:";
print_r($arr);
echo "\n";
echo "去重排序后\n";
print_r(mySort(myDr($arr)));
function myDr($arr) {
$arrTemp = array();
for ($i = 0;$i < count($arr);$i++) {
$state = true;
for ($j = $i + 1;$j < count($arr);$j++) {
if ($arr[$i] == $arr[$j]) {
$state = false;
break;
}
}
if ($state) {
array_push($arrTemp, $arr[$i]);
}
}
return $arrTemp;
}
function mySort($arr) {
$temp = 0;
for ($i = 0;$i < count($arr);$i++) {
for ($j = $i + 1;$j < count($arr);$j++) {
if ($arr[$i] > $arr[$j]) {
$temp = $arr[$i];
$arr[$i] = $arr[$j];
$arr[$j] = $temp;
}
}
}
return $arr;
}