$key_to_search : Required , key to search inside the $input_array.
$input_array : Required , array inside which the key will be searched.
Output is TRUE if key is found inside array , otherwise FALSE
Example 1
$input=array(1,2,3,4);
if(array_key_exists(2,$input)){
echo "Key is available ";
}else{
echo "Key is NOT available ";
}
Output is here.
Key is available
Example 2
$input=array('One' ,'Two','Three');
if(array_key_exists(0,$input)){
echo "Key is available ";
}else{
echo "Key is NOT available ";
}
Output is here
Key is available
Example 3
$input=array('One' =>1,'Two'=>2,'Three'=>3,'Four'=>'Fourth');
if(array_key_exists('Three',$input)){
echo "Key is available ";
}else{
echo "Key is NOT available ";
}
Output is here.
Key is available
array_key_exists and Null value
For Null value array_key_exist() returns True, however isset() returns False
$input=array('One' =>1,'Two'=>null);
if(array_key_exists('Two',$input)){ // True
echo "Key is available "; // this is the output
}else{
echo "Key is NOT available ";
}
echo "<br>";
////
echo var_dump(isset($input['Two'])); // bool(false)