how to check value in array in php code example
Example 1: php in array
$colors = array("red", "blue", "green");
if (in_array("red", $colors)) {
echo "found red in array";
}
Example 2: in_array
<?php
/**
in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool
*/
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
Example 3: in_array
<?
in_array("Irix", $os);
?>