Home Tutorial Php Phparray php array contains key

 
 

Share on Google+Share on Google+
php array contains key
Posted on: October 28, 2009 at 12:00 AM
Advertisement
This section demonstrates the use of array_key_exists() function in php

  • array_key_exists() function is used to check whether the given key is present in the given array or not.


PHP Array Contains Key Example

<?php

      $ar=array("d"=>"daisy","m"=>"marigold","r"=>"rose","l"=>"lotus");

      $b=array_key_exists("r",$ar);

       if($b){

        echo "r is key in the array";

       }

      else

      echo "r is not the key in the array";

      echo"<br>";

       $b1=array_key_exists("a",$ar);

      if($b1){

       echo "a is key in the array"

       }

      else {

      echo "a is not the key in the array";

     }

?>

Output
r is key in the array
a is not the key in the array
Advertisement

Related Tags for php array contains key:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 28, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com