Checking for an element with a particular value : in_array « Data Structure « PHP






Checking for an element with a particular value

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


if (in_array(3, $meals)) {
  print 'There is a $3 item.';
}

if (in_array('F', $books)) {
  print "We have F";
}
// in_array() is case-sensitive
if (in_array("f", $books)) {
  print "We have the f.";
}
?>
  
  








Related examples in the same category

1.in_array( ) function return true if an array contains a specific value
2.in_array() function is a control statement.
3.Determining Whether an Element Is in an Array
4.Locating Array Elements