PHP - Function array_key_exists()


Advertisements


Syntax

bool array_key_exists ( $key, $array );

Definition and Usage

It returns TRUE if the given key is set in the array.

Parameters

Sr.No Parameter & Description
1

key(Required)

The key to be searched.

2

array(Required)

This is an array to be searched

Return Values

It Returns TRUE if the given key is set in the array otherwise FALSE.

Example

Try out following example −

<?php
   $input = array('first' => 10, 'second' => 400);
   
   if (array_key_exists('first', $input)) {
      echo "The 'first' element is in the array";
   }
?> 

This will produce the following result −

The 'first' element is in the array

php_function_reference.htm

Advertisements