Home How To Check key Exist in Array in PHP?

How To Check key Exist in Array in PHP?

78 viewsPHP
1

we have an array we want need to check key(Apple) exists in the array, so we will use array_key_exists() built function of PHP who help to check whether key exists in the array. you can also learn more about array_key_exists() from here.

How To Check key Exist in Array in PHP?

<?php
$a=array("fruit"=>"Apple","Car"=>"BMW");
if (array_key_exists("Apple",$a))
  {
  echo "Array Key exists!";
  }
else
  {
  echo "Array Key does not exist!";
  }
?>

Output

Array Key does not exist!

Note: We have key fruit, car and we are checking Apple in the array, so apple is not existing in array!

Changed status to publish