日期:2011-11-24  浏览次数:20445 次

定义和用法
in_array() 函数在数组中搜索给定的值。
语法
in_array(value,array,type)

参数     描述
value     必需。规定要在数组搜索的值。
array     必需。规定要搜索的数组。
type     可选。如果设置该参数为 true,则检查搜索的数据与数组的值的类型是否相同。
说明
如果给定的值 value 存在于数组 array 中则返回 true。如果第三个参数设置为 true,函数只有在元素存在于数组中且数据类型与给定值相同时才返回 true。
如果没有在数组中找到参数,函数返回 false。
注释:如果 value 参数是字符串,且 type 参数设置为 true,则搜索区分大小写。
例子
<?php
$planet = array(
'jsp',
'php',
'asp'
);

$temp = 'php';

if(in_array('php',$planet))
{
    echo 'php 存在于数组$planet中';
    echo '<br/>';
    echo '<br/>';
}
if(in_array($temp,$planet))
{
    echo $temp.'存在于数组$planet中';
    echo '<br/>';
    echo '<br/>';
}
else
{
    echo $temp.'不存在于数组$planet中';
    echo '<br/>';
    echo '<br/>';
}
?>
输出:
php 存在于数组$planet中
php存在于数组$planet中