in_array() function is used to check whether the given value is presesnt in the array or not.
Example
<?php
$ar1=array("jack","mac","rob","tom","jennifer");
$val="mac";
$val1="mic";
foreach ($ar1 as $a)
echo " ".$a;
echo "<br>";
if(in_array($val,$ar1)) {
echo "$val is present in the array";
}
else {
echo "$val is not present in the array";
}
echo "<br>";
if(in_array($val1,$ar1)) {
echo "$val1 is present in the array";
}
else {
echo "$val1 is not present in the array";
}
?>
Output
jack mac rob tom jennifer
mac is present in the array
mic is not present in the array
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.