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