How to use array key exists in PHP

In this article, I will explain how the array_key_exists() function can be used in PHP.
  • 1610

array_key_exists() function in PHP

  • The array_key_exists() function is used to checks an array for a specified key.

  • The array_key_exists() function is returns true if the key exists and false if the key does not exist.

Syntax

array_key_exists(key,array)

Parameter

  • key key is required parameter. Key to be searched.

  • array  array is required parameter. The array determine whose keys will be checked.

Example

The following example show to how the array_key_exists() function can be used in PHP.

<html>

<body>

<h3 style="color: darkseagreen;">array_key_exists() function example in PHP</h3>

    <?php

    $a=array("a"=>"Nitin","b"=>"Ravi");

    if (array_key_exists("a",$a))

     {

     echo "Array key exists!";

     }

    else

     {

     echo "Array key does not exist!";

     }

    ?>

</body>

</html>

 

Output

exit.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.