php数组函数序列之in_array() 查找数组值是否存在
in_array() 定义和用法
in_array() 函数在数组中搜索给定的值。
语法
in_array(value,array,type)
参数 描述
value 必需。规定要在数组搜索的值。
array 必需。规定要搜索的数组。
type 可选。如果设置该参数为 true,则检查搜索的数据与数组的值的类型是否相同。
说明
如果给定的值 value 存在于数组 array 中则返回 true。如果第三个参数设置为 true,函数只有在元素存在于数组中且数据类型与给定值相同时才返回 true。
如果没有在数组中找到参数,函数返回 false。
注释:如果 value 参数是字符串,且 type 参数设置为 true,则搜索区分大小写。
例子 1
<?php
$people = array("peter", "joe", "glenn", "cleveland");
if (in_array("glenn",$people))
{
echo "match found";
}
else
{
echo "match not found";
}
?>
输出:
match found
例子 2
<?php
$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 />";
}
?>
输出:
match not found
match found
match found
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
-
-
荐
数据库的设计
数据库的设计一 为什么需要规范的数据库设计数据库设计的步骤收集信息标识实体标识每个实体需要存储的详细信息标识实体...
[阅读全文]
-
-
-
-
网友评论