Array_keys::P HP All key combinations new array

Source: Internet
Author: User

In the PHP array, if you want to extract all the key values from the array to form a new array, you can use the Array_keys function.

function usage such as:

Array_keys (Array,value)


This is how it is presented in the list:

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.


<?php$color=array ("B" = "blur", "P" = "Pink", "R" and "Red");p Rint_r (Array_keys ($color, "Red")); >


Results:

Array ([0] = R)



The strict parameter is specified as false, and PHP does not use the congruent comparison (= = =) to strictly check the data type of the key value.

Use the strict parameter (false):

<?php$num=array ("1");p Rint_r (Array_keys ($num, "1", false));? >

Output:

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


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

Use the strict parameter (true):

<?php$num=array ("1");p Rint_r (Array_keys ($num, "1", true));? >

Output:

Array ([0] = 3)


Array_keys::P HP All key combinations new array

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.