<?php
echo "欢迎您和我们一起学习PHP!";
echo "<hr color='#FF00FF' />";
//第一种方法
$numbers = range (0,100);
shuffle ($numbers);
//array_slice 取该数组中的某一段
echo "排序前:";
$no=20;
$result = array_slice($numbers,0,$no);
for ($i=0;$i<$no;$i++){
echo "<font color='#0000BB'>".$result[$i]."</font>"."\n";
}
echo "<br />";
echo "排序后:";
sort ($result);
//echo "<font color='#FF0000'>".join (' ',$result)."</font>";
for ($w=0;$w<$no;$w++){
echo "<font color='#FF0000'>".$result[$w]."</font>"."\n";
}
echo"<hr />";
//第二种方法
$tmp=array();
while(count($tmp)<20){
$tmp[]=mt_rand(0,100);
$tmp=array_unique($tmp);
}
echo "排序前:";
echo join(',',$tmp);
echo "<br>";
echo "排序后:" ;
sort($tmp);
echo implode(',',$tmp);
?>