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

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

Jun 06, 2016 pm 08:39 PM
array_search Return key name

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

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
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 admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)