php in_array() 檢查數組中是否存在某個值
in_array檢查數組中是否存在某個值
基本語法:
bool in_array(mixed $needle,array $haystack,bool $strict=FALSE)
在 haystack 中搜索 needle
參數介紹
返回值
如果找到 needle 則返回 TRUE ,否則返回 FALSE 。
實例:
<?php
$os = array(
"Mac",
"NT",
"Irix",
"Linux"
);
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
在線運行第二個條件失敗,因為 in_array() 是區分大小寫的,所以以上程序顯示為:
Got Irix
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!