Checks if a value exists in an array in PHP
Description
The following code shows how to checks if a value exists in an array.
Example
//from w w w .java 2s . co m
<?php
$people = array("XML", "CSS", "Java", "Javascript", 23);
if (in_array("23", $people, TRUE)){
echo "Match found<br>";
}else{
echo "Match not found<br>";
}
if (in_array("Glenn",$people, TRUE)){
echo "Match found<br>";
}else{
echo "Match not found<br>";
}
if (in_array(23,$people, TRUE)){
echo "Match found<br>";
}else{
echo "Match not found<br>";
}
?>
The code above generates the following result.