PHP array function array_key_exists() finds whether the array key exists

WBOY
Release: 2016-07-25 09:12:49
Original
1090 people have browsed it

Contents of this section: PHP array function array_key_exists()

array_key_exists() definition and usage The array_key_exists() function determines whether the specified key exists in an array. If the key exists, it returns true, otherwise it returns false.

Grammar array_key_exists(key,array) Parameter Description key is required. Specifies the key name. array required. Specifies the input array.

Example 1, PHP array function array_key_exists().

  1. $a=array("a"=>"Dog","b"=>"Cat");
  2. if (array_key_exists("a",$a))
  3. {
  4. echo "Key exists!";
  5. }
  6. else
  7. {
  8. echo "Key does not exist!";
  9. }
  10. ?>
Copy code

Output: Key exists!

Example 2, PHP array function array_key_exists().

  1. $a=array("a"=>"Dog","b"=>"Cat");
  2. if (array_key_exists("c",$a))
  3. {
  4. echo "Key exists!";
  5. }
  6. else
  7. {
  8. echo "Key does not exist!";
  9. }
  10. ?>
Copy code

Output: Key does not exist!

Example 3, PHP array function array_key_exists().

  1. $a=array("Dog",Cat");
  2. if (array_key_exists(0,$a))
  3. {
  4. echo "Key exists!";
  5. }
  6. else
  7. {
  8. echo "Key does not exist!";
  9. }
  10. ?>
Copy code

Output: Key exists!



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!