PHP searches for the given simple instance array_search function in the array, array array_search_PHP tutorial

Source: Internet
Author: User
PHP searches for the given simple instance array_search function in the array, array array_search. PHP searches for the given simple instance array_search function in the array. the array array_searcharray_search () PHParray_search () function is used to search for the given value in the array, if it succeeds, return to PHP to search for the given simple instance array_search function in the array, array array_search

Array_search ()

The PHP array_search () function is used to search for a given value in the array. if the value is successful, the corresponding key name is returned. otherwise, FALSE is returned.

Syntax:

Mixed array_search (mixed needle, array [, bool strict]) parameter description:

Parameters Description
Needle The value to be searched in the array. if it is a string, it is case sensitive.
Array Array to be retrieved
Strict Optional. If this parameter is set to TRUE, the needle and array value types are checked.

Because the starting index number of the index array may be 0, this function may return non-Boolean values equivalent to FALSE, such as 0 or "", therefore, you must use the = operator to strictly verify the value returned by the function.

Example:

<? Php $ arr_a = array (0 => "a", 1 => "B", 2 => "c"); $ key = array_search ("", $ arr_a); if ($ key! = FALSE) {echo "key name: $ key";} else {echo 'no matching result';}?>

The output result is as follows:

Key name: 0 if needle appears more than once in array, the first matched Key is returned. To return keys of all matched values, use the array_keys () function.

The above PHP search for the given simple instance array_search function in the array is all the content shared by the editor. I hope you can give us a reference and support for the help house.

The http://www.bkjia.com/PHPjc/1136642.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1136642.htmlTechArticlePHP searches for the given simple instance array_search function in the array, the array array_search () PHP array_search () function is used to search for the given value in the array, if successful, return...

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.