php数组函数序列之array_search()- 按元素值返回键名_PHP教程

WBOY
Release: 2016-07-21 15:23:42
Original
856 people have browsed it

array_search()定义和用法
array_search() 函数与 in_array() 一样,在数组中查找一个键值。如果找到了该值,匹配元素的键名会被返回。如果没找到,则返回 false。

在 PHP 4.2.0 之前,函数在失败时返回 null 而不是 false。

如果第三个参数 strict 被指定为 true,则只有在数据类型和值都一致时才返回相应元素的键名。

语法
array_search(value,array,strict)参数 描述
value 必需。规定在数组中搜索的值。
array 必需。被搜索的数组。
strict 可选。可能的值:

true
false - 默认
如果值设置为 true,还将在数组中检查给定值的类型。(参见例子 2)


例子 1

复制代码 代码如下:

$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
echo array_search("Dog",$a);
?>

输出:

a

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/324437.htmlTechArticlearray_search()定义和用法 array_search() 函数与 in_array() 一样,在数组中查找一个键值。如果找到了该值,匹配元素的键名会被返回。如果没找到...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!