Let's take a look at the In_array. Check if a value exists in the array
The code is as follows
<?php
$os = Array ("Mac", "NT", "Irix", "Linux");
echo "(1)";
if (In_array ("Irix", $os)) {
echo "Got Irix";
}
if (In_array ("Mac", $os)) {//in_array () is case-sensitive
echo "Got mac";
}
$a = Array (' 1.10 ', 12.4, 1.13);
echo "(2)";
if (In_array (' 12.4 ', $a, true)) {//in_array () strict type checking
echo "' 12.4 ' found with strict checkn";
}
if (In_array (1.13, $a, true)) {
echo "1.13 found with strict checkn";
}
$a = array (' P ', ' h '), Array (' P ', ' r '), ' o ');
echo "(3)";
if (in_array array (' P ', ' h '), $a)) {
echo "' ph ' was foundn ';
}
if (In_array array (' f ', ' I '), $a)) {//in_array () is used as an array needle
echo "' fi ' was Foundn";
}
if (In_array (' o ', $a)) {
echo "' O ' was Foundn";
}
?>
The results of the program run are:
(1) Got Irix
(2) 1.13 found with strict check
(3) ' ph ' was found ' o ' is found
They're all one-dimensional arrays. It's easy to see if the multidimensional data has a value
The code is as follows
$arr = Array (
Array (' A ', ' B '),
Array (' C ', ' d ')
);
In_array (' A ', $arr); The return is always false at this time
Deep_in_array (' A ', $arr); Returns a value of true at this time
function Deep_in_array ($value, $array) {
foreach ($array as $item) {
if (!is_array ($item)) {
if ($item = = $value) {
return true;
} else {
Continue
}
}
if (In_array ($value, $item)) {
return true;
else if (Deep_in_array ($value, $item)) {
return true;
}
}
return false;
}
This method is in the PHP Help manual In_array method detailed page comments see, usually nothing more to see the Help manual, especially behind the classic comments, which collected a lot of people's classic methods Ah.