Home  >  Article  >  Backend Development  >  php-Arrays function-array_search-finds a given value in an array and returns the corresponding key name_PHP tutorial

php-Arrays function-array_search-finds a given value in an array and returns the corresponding key name_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:51:251030browse

array_search() finds the given value in the array and returns the corresponding key name

【Function】
This function will search for a given value in the specified array and return the key name of the value if found, otherwise it will return false.
【Scope of use】
​​​​ php4>=4.0.5, php5.
【Use】
             mixed array_search( mixed needle,array haystack[,bool strict] )
            needle/required/value to be found
               haystack/required/original array of the upcoming search operation
             strict/optional/true, the function will also check the type of needle in haystack
                                                                                                                                                                                                                                                                If needle appearing more than once in haystack, return the first matching construct
【Example】
[php]
$array=array('blue','red','green','red');
echo $key=array_search('green',$array);
echo "n";
echo $key=array_search('red',$array,false);
/*
2
1
*/


Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478190.htmlTechArticlearray_search() Find the given value in the array and return the corresponding key name [Function] This function will be in Searches for a given value in the specified array and returns the value if found...
Statement:
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