Array key Exists Function in PHP

In this article I explain array key exists function in PHP.
  • 2195

PHP array_key_exists Function

The PHP array_key_exists function deterimes whether the specified key or index exists in the given array or not and returns true if it exists otherwise false.

Syntax

array_key_exists(key, array)

Parameters

The parameters of the array_key_exists function are:

Parameter Description
key It specifies key.
array It  specifies an array.

Example

An example of the array_key_exists function is:

<?php
echo
 "<pre>";
$
val = array("a" => "Apple", "b" => "Mango", "c" => "Orange", "Banana");
if(array_key_exists("a
",$val))
{
echo "
Key exists!";
}
else
{
echo "key
 does not exists!";
}

?>

Output

array-key-exists-function-in-php.jpg

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.