做個PHP的練習筆記:排序及搜尋一組陣列內的號碼... <?php //降冪排序 $arr=array(12,45,89,3,24,55,223,76,22,11,89,2,4,5,28,112,20,434); for ($i = max($arr); $i >= 0; $i--){ if (in_array($i, $arr)) echo $i." "; } ?> <?php //升冪排序 $arr=array(12,45,89,3,24,55,223,76,22,11,89,2,4,5,28,112,20,434); for ($i = 0; $i <= max($arr); $i++){ if (in_array($i, $arr)){ echo $i." "; } } ?> <?php $num=20; //要找的數字 $arr=array(12,45,89,3,24,55,223,76,22,11,89,2,4,5,28,112,20,434); if(in_array($num,$arr)){ for ($i = 0; $i <= count($arr); $i++){ if($arr[$i]==$num){ echo "第{$i}元素是{$arr[$i]}"; return false; } } }else{ echo"找不到:{$num}"; } ?>