(PHP 4, PHP 5, PHP 7)
in_array — 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷欠锟斤拷锟斤拷某锟斤拷值
锟斤拷锟斤拷锟诫,锟节大海o拷haystack
锟斤拷锟斤拷锟斤拷锟斤拷锟诫(
needle
锟斤拷锟斤拷锟斤拷锟矫伙拷锟斤拷锟斤拷锟� strict
锟斤拷使锟矫匡拷锟缴的比较★拷
needle
锟斤拷锟斤拷锟斤拷锟斤拷值锟斤拷
Note:
锟斤拷锟�
needle
锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷冉锟斤拷锟斤拷锟斤拷执锟叫⌒达拷摹锟�
haystack
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟介。
strict
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� strict
锟斤拷值为
TRUE
锟斤拷 in_array() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
needle
锟斤拷锟斤拷锟斤拷锟角凤拷锟�
haystack
锟叫碉拷锟斤拷同锟斤拷
锟斤拷锟斤拷业锟� needle
锟津返伙拷 TRUE
锟斤拷锟斤拷锟津返伙拷 FALSE
锟斤拷
Example #1 in_array() 锟斤拷锟斤拷
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
锟节讹拷锟斤拷锟斤拷锟斤拷失锟杰o拷锟斤拷为 in_array() 锟斤拷锟斤拷锟街达拷小写锟侥o拷锟斤拷锟斤拷锟斤拷锟较筹拷锟斤拷锟斤拷示为锟斤拷
Got Irix
Example #2 in_array() 锟较革拷锟斤拷锟酵硷拷锟斤拷锟斤拷锟�
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true)) {
echo "'12.4' found with strict check\n";
}
if (in_array(1.13, $a, true)) {
echo "1.13 found with strict check\n";
}
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
1.13 found with strict check
Example #3 in_array() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为 needle
<?php
$a = array(array('p', 'h'), array('p', 'r'), 'o');
if (in_array(array('p', 'h'), $a)) {
echo "'ph' was found\n";
}
if (in_array(array('f', 'i'), $a)) {
echo "'fi' was found\n";
}
if (in_array('o', $a)) {
echo "'o' was found\n";
}
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
'ph' was found 'o' was found