in_array( ) function return true if an array contains a specific value : in_array « Data Structure « PHP






in_array( ) function return true if an array contains a specific value

 
//bool in_array ( mixed needle, array haystack [, bool strict] )

<?
    $needle = "Sam";
    $haystack = array("Johnny", "Timmy", "Bobby", "Sam", "Tammy", "Joe");

    if (in_array($needle, $haystack)) {
            print "$needle is in the array!\n";
    } else {
            print "$needle is not in the array\n";
    }
?>
  
  








Related examples in the same category

1.Checking for an element with a particular value
2.in_array() function is a control statement.
3.Determining Whether an Element Is in an Array
4.Locating Array Elements