"Orange","Banana","Grape","Apple","Flower");
////////////////////////////////////////////////
echo "
//搜尋字串:不用計數器的while迴圈,印出陣列:
";
$txt="Apple2";
while(list($key,$v) = each($fruit)){
if($v==$txt){
echo "找到 $txt";
break;
}
if($key==count($fruit)){
echo "沒有找到 $txt";
}
}
echo "
";
////////////////////////////////////////////////
echo "
//搜尋字串:用函數:\$key = array_search('字串',陣列)。\$key是找到的位置,找不到傳回false
";
$txt="Apple3";
$key = array_search($txt,$fruit);
if($key==false) echo "找不到".$txt;
else echo "找到".$txt.",在第".$key."個位置";
?>