array_key_exists function in php
×


array_key_exists function in php

1824

array_key_exists function in PHP used find whether a particular key or index is exist in array or not.

  1. It is an inbuilt function of PHP with two parameters.
  2. Return type of array_key_exists  function is Boolean means it can return either TRUE or FALSE.
  3. If the given key is present in the array , then array_key_exists  function returns TRUE Otherwise it returns FALSE.

Syntax:

array_key_exists(arr_key, arr);

Here

arr is the array in which we search the existence of a particular key and arr_key parameter represent that key which we want to search.


Example 1:

<?php
$arr=array("Ram"=>"1231","Shyam"=>"1232","Deepak"=>"1233","Divya"=>"1234","Radha"=>"1235"); // employees name with ID
$key="Radha";
if(array_key_exists($key,$arr)){
   echo "The employee ID of ".$key." is ".$arr[$key];
}else{
   echo $key." is not exist";
}
?>

Output:


Example 2:

<?php
$arr=array("Ram","Shyam","Deepak","Divya","Radha"); // employees name 
if(array_key_exists(3,$arr)){
  echo "The employee ".$arr[3]." is exist";
}else{
  echo "not exist";
}
?>

Output:




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments