Home > Backend Development > PHP Tutorial > PHP array function array_key_exists() finds whether the array key exists

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

WBOY
Release: 2016-07-25 09:04:50
Original
1100 people have browsed it
  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:

  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:

  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