Php array function sequence: array_search ()-Return key by element value _ PHP Tutorial

Source: Internet
Author: User
Array_search () of the php array function sequence-return key name by element value. Array_search () defines and uses the array_search () function and the in_array () function to find a key value in the array. If this value is found, the key name of the matching element is returned. If the definition and usage of array_search () are not found
The array_search () function is the same as the in_array () function. you can find a key value in the array. If this value is found, the key name of the matching element is returned. If not found, false is returned.

Before PHP 4.2.0, the function returns null instead of false in case of failure.

If the third parameter strict is set to true, the key name of the corresponding element is returned only when the data type and value are consistent.

Syntax
Array_search (value, array, strict) parameter description
Value is required. Specifies the value to be searched in the array.
Array is required. The searched array.
Strict is optional. Possible values:

True
False-default
If the value is set to true, the type of the given value is also checked in the array. (See example 2)


Example 1

The code is as follows:


$ A = array ("a" => "Dog", "B" => "Cat", "c" => "Horse ");
Echo array_search ("Dog", $ );
?>


Output:

A

The http://www.bkjia.com/PHPjc/324437.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324437.htmlTechArticlearray_search () defines and uses the array_search () function, like in_array (), to find a key value in the array. If this value is found, the key name of the matching element is returned. If no...

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.