in_array()
对于该函数,看似简单,但是需要注意以下问题
1.该函数是区分大小写的
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
2.强类型的,对于该函数,“12”与12为两个不同的项
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true)) {
echo "'12.4' found with strict check ";
}
if (in_array(1.13, $a, true)) {
echo "1.13 found with strict check ";
}
?>
3.如果出现数组
<?php
$a = array(array('p', 'h'), array('p', 'r'), 'o');
if (in_array(array('p', 'h'), $a)) {
echo "'ph' was found ";
}
if (in_array(array('f', 'i'), $a)) {
echo "'fi' was found ";
}
if (in_array('o', $a)) {
echo "'o' was found ";
}
?>