PHP array operation get array element index value _php Tutorial

Source: Internet
Author: User
If we want to get the index value quickly, we can use the PHP array_values () function, which can quickly and concisely help us find what we want. Let's take a look at the use of the Array_values () function

The Array_keys () function returns a new array that contains all the key names in the array.

If the second argument is supplied, only the key name of the value is returned.

If the strict parameter is specified as true, PHP uses the congruent comparison (= = =) to strictly check the data type of the key value.

Grammar
Array_keys (array,value) parameter description
Array required. Specifies the input array.
Value is optional. The index (key) of the specified value.
Strict is optional. Used with the value parameter. Possible values:

True-Returns the key name with the specified value, based on the type.
False-The default value. Does not depend on the type.

Example 1

The code is as follows Copy Code

$a =array ("a" = "Horse", "b" = "Cat", "C" and "Dog");
Print_r (Array_keys ($a));
?>

Output:

Array ([0] = a [1] = b [2] = = c)

Example 2
Use the value parameter:

The code is as follows Copy Code

$a =array ("a" = "Horse", "b" = "Cat", "C" and "Dog");
Print_r (Array_keys ($a, "Dog"));
?>

Output:

Array ([0] + = c)

Example 3
Use the strict parameter (false):

The code is as follows Copy Code

$a =array (10,20,30, "10");
Print_r (Array_keys ($a, "ten", false));
?>

Output:

Array ([0] = 0 [1] = 3)

Example 4
Use the strict parameter (true):

The code is as follows Copy Code

$a =array (10,20,30, "10");
Print_r (Array_keys ($a, "ten", true));
?>

Output:

Array ([0] = 3)

http://www.bkjia.com/PHPjc/631307.html www.bkjia.com true http://www.bkjia.com/PHPjc/631307.html techarticle if we want to get the index value quickly, we can use the PHP array_values () function, which can quickly and concisely help us find what we want. Let's take a look at ...

  • Related Article

    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.