Checking for an element with a particular key : array_key_exists « Data Structure « PHP






Checking for an element with a particular key

 
<?
$meals = array('A' => 1,
               'B' => 4.95,
               'C' => 3.00,
               'D' => 6.50,
               'E' => 0); // Shrimp Puffs are free!
$books = array("F",'G');

if (array_key_exists('A',$meals)) {
    print "Yes, we have A";
}

if (array_key_exists('B',$meals)) {
    print "We have a B";
}

if (array_key_exists(1, $books)) {
    print "Element 1 is How to Cook in Eat in Chinese";
}
?>
  
  








Related examples in the same category

1.Checking a
2.Validating a drop-down menu with array_key_exists()
3.Testing for the Existence of a Key in an Array