pTutorial

New way to learn Programming

How To Check Key Exist In Array PHP

how to check key exist in array PHP

In PHP array_key_exists() function is used to check whether a particular key is exist or not. Return true if key exists otherwise return false.

PHP array_key_exists function

<?php
$temp=array("hero"=>"ZMR","ktm"=>"Duke");
if (array_key_exists("ktm",$temp)){
	echo "The Key is valid";
}
else{
	echo "The Key is not valid!";
}
?>

Output

The Key is valid

Explanation

You can also use isset() function to check whether key is exist or not.

Note: The array_key_exists function is case sensitive that means ktm and KTM are not same.

See Also


QUOTES OF THE DAY

Tomorrow life is too late, live today.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER