PHP searches the array for a given simple instance Array_search function, array array_search_php tutorial

Source: Internet
Author: User

PHP searches the array for a given simple instance of the Array_search function, array array_search


Array_search ()

The PHP Array_search () function is used to search the array for the given value, and if successful returns the corresponding key name, otherwise FALSE.

Grammar:

Mixed Array_search (mixed needle, array array [, BOOL strict]) parameter description:

Parameters Description
Needle The value that needs to be searched in the array, if it is a string, is case-sensitive
Array The array to retrieve
Strict Optional, if set to TRUE, the value types in the needle and array are also checked

Because the index array may have a starting index number of 0, the function may also return a non-Boolean value equivalent to FALSE, such as 0 or "", so you need to use the = = = operator to rigorously validate the value returned by the function.

Example:

<?php$arr_a = Array (0 = "a", 1 = "B", 2 = "C"), $key = Array_search ("A", $arr _a), if ($key!== FALSE) {  E Cho "Key name: $key";} else {  echo ' no match result ';}? >

The example output is as follows:

Key Name: 0 if needle occurs more than once in an array, the first matching key is returned. To return all keys that match a value, use the Array_keys () function.

The above PHP in the array to search for a given simple instance array_search function is the small part of the whole content to share to everyone, I hope to give you a reference, but also hope that we have a lot of support to help the home.

http://www.bkjia.com/PHPjc/1136642.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136642.html techarticle PHP searches the array for a given simple instance of the Array_search function, the array array_search array_search () PHP Array_search () function is used to search the array for a given value, and if successful then 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.