in_array()
函数用于在数组中搜索给定的字符串。
如果在数组中找到给定的字符串,则返回 TRUE,否则返回 FALSE。
on
it
road
.com
PHP in_array函数 语法
in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool
除非设置了严格的条件($strict),否则使用松散的比较在haystack (干草堆)中搜索needle(针)。
PHP in_array函数 参数
needle
待搜索的值。
如果 needle 是字符串,则比较是区分大小写的。
haystack
待搜索的数组。
strict
如果第三个参数 strict 的值为 TRUE, 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。
示例
<?php $os = array("Mac", "Windows", "Solaris", "Linux"); if (in_array("Solaris", $os)) { echo "Found Solaris"; } if (in_array("linux", $os)) { echo "Found linux"; } ?>
注意,默认查找时是区分大小写的,所以只输出:
Found Solaris
日期:2020-09-17 00:10:29 来源:oir作者:oir