PHP array_key_exists checks whether the key name or index exists in the array. arraykeyexists

Source: Internet
Author: User

PHP array_key_exists checks whether the key name or index exists in the array. arraykeyexists

Array_key_exists ()

The PHP array_key_exists () function is used to check whether the given key name or index exists in the array. If yes, TRUE is returned; otherwise, FALSE is returned.

Syntax:

The bool array_key_exists (mixed key, array search) parameter key is the given key name or index and can be any value that can be used as an array index.

The array_key_exists () function can also be used for objects.

Example:

<? Php $ arr_a = array ('id' => 1, 'name' => "admin"); if (array_key_exists ('name', $ arr_a )) {echo 'key name exists in array $ arr_a';} else {echo 'key name does not exist in array $ arr_a';}?>

The output result is as follows:

The key name exists in the array $ arr_a. The array_key_exists () function returns TRUE for the array element whose value is null. To check whether the array element is null, use isset ().

The above PHP array_key_exists method to check whether the key name or index exists in the array is all the content shared by the editor. I hope to give you a reference and support for the house of friends.

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.