PHP in_array() 函数
PHP 教程
· 2019-01-22 19:26:34
实例
在数组中搜索值 "codercto" ,并输出一些文本:
$sites = array("Google", "codercto", "Taobao", "Facebook");
if (in_array("codercto", $sites))
{
echo "找到匹配项!";
}
else
{
echo "没有找到匹配项!";
}
运行实例 »
定义和用法
in_array() 函数搜索数组中是否存在指定的值。
语法
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
| 参数 | 描述 |
|---|---|
| needle | 必需。规定要在数组搜索的值。 |
| haystack | 必需。规定要搜索的数组。 |
| strict | 可选。如果该参数设置为 TRUE,则 in_array() 函数检查搜索的数据与数组的值的类型是否相同。 |
技术细节
| 返回值: | 如果在数组中找到值则返回 TRUE,否则返回 FALSE。 |
|---|---|
| PHP 版本: | 4+ |
| 更新日志 | 自 PHP 4.2 起,search 参数可以是一个数组。 |
更多实例
实例 1
使用所有的参数:
$people = array("Peter", "Joe", "Glenn", "Cleveland", 23);
if (in_array("23", $people, TRUE))
{
echo "Match found<br>";
}
else
{
echo "Match not found<br>";
}
if (in_array("Glenn",$people, TRUE))
{
echo "Match found<br>";
}
else
{
echo "Match not found<br>";
}
if (in_array(23,$people, TRUE))
{
echo "Match found<br>";
}
else
{
echo "Match not found<br>";
}
点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html
Hit Refresh
Satya Nadella、Greg Shaw / HarperBusiness / 2017-9-26 / USD 20.37
Hit Refresh is about individual change, about the transformation happening inside of Microsoft and the technology that will soon impact all of our lives—the arrival of the most exciting and disruptive......一起来看看 《Hit Refresh》 这本书的介绍吧!