PHP - Function array_key_exists()


Advertisements


Syntax

bool array_key_exists ( $key, $array );

Definition and Usage

Returns TRUE if the given key is set in the array. key can be any value possible for an array index.

Parameters

Sr.No Parameter & Description
1

key

Required. Key to be searched.

2

array

Required. Array to be searched

Return Values

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

Example

Try out following example −

<?php
   $search_array = array('first' => 1, 'second' => 4);
   
   if (array_key_exists('first', $search_array)) {
      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