"Orange","Banana","Grape","Apple","Flower"); //////////////////////////////////////////////// echo "
//搜尋字串,不用迴圈,用函數:array_search(陣列)
"; $txt="Apple2"; if(array_search($txt,$fruit) ==0){ echo "沒有找到 $txt"; }else{ echo "找到 $txt"; } echo "

"; //////////////////////////////////////////////// echo "
//方法二,一樣方法,函數:array_search(陣列)
"; $txt="Grape"; if( ($key =array_search($txt,$fruit)) !=0){ echo "找到 $txt"; }else{ echo "沒有找到 $txt"; } ?>