Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function array_key_exists()


previous

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.

Paramters

ParameterDescription
keyRequired. Key to be searched.
arrayRequired. 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 following result:

The 'first' element is in the array

previous Printer Friendly

Advertisements


  

Advertisements