Php-Arrays function-array_search-find the given value in the array and return the corresponding key name

Source: Internet
Author: User
Array_search () searches for a given value in the array and returns the corresponding key name. [function] This function searches for a given value in the specified array, if it is found, the key name of the value is returned. otherwise, false is returned. [Scope of use] php4 & gt; 4.0.5, php5. [use] mixed... SyntaxHighlighter

Array_search () searches for the given value in the array and returns the corresponding key name.

[Function]
This function searches for a given value in the specified array and returns the key name of the value if it is found. otherwise, false is returned.
Scope of use]
Php4> = 4.0.5, php5.
[Use]
Mixed array_search (mixed needle, array haystack [, bool strict])
Needle/required/value to be searched
Haystack/required/original array to be searched
Strict/optional/true then the function will also check the needle type in haystack
If needle appears more than once in the haystack, the first matched creation is returned.
[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
*/

 


Taken from zuodefeng's note

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.