PHP array function sequence array_search()-return key name by element value_PHP tutorial

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

array_search() definition and usage
array_search() function is the same as in_array(), searching for a key value in the array. If the value is found, the key of the matching element is returned. If not found, returns false.

Prior to PHP 4.2.0, functions returned null instead of false on failure.

If the third parameter strict is specified as true, the key name of the corresponding element will only be returned if the data type and value are consistent.

Syntax
array_search(value,array,strict) Parameter Description
value Required. Specifies the value to search for in the array.
array required. The array to be searched.
strict optional. Possible values:

true
false - Default
If the value is set to true, the type of the given value will also be checked in the array. (See Example 2)


Example 1

Copy code The code is as follows:

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

Output:

a

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324437.htmlTechArticlearray_search() definition and usage array_search() function is the same as in_array(), searching for a key value in the array. If the value is found, the key of the matching element is returned. If not found...
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 admin@php.cn
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!