Home > php教程 > php手册 > PHP array_key_exists() 函数

PHP array_key_exists() 函数

WBOY
Release: 2016-06-21 08:52:37
Original
1253 people have browsed it

定义和用法
array_key_exists() 函数判断某个数组中是否存在指定的 key,如果该 key 存在,则返回 true,否则返回 false。
语法
array_key_exists(key,array)

参数     描述
key     必需。规定键名。
array     必需。规定输入的数组。
例子
$olympic = array(
'Barcelona'=>1992,
'Atlanta'=>1996,
'Sydney'=>2000,
'Athens'=>2004,
'Beijing'=>2008
);

$city = array(
'Rome',
'Athens',
'Shanghai'
);

foreach($city as $c)
{
    if(array_key_exists($c, $olympic))
    {
        echo $c.'是数组olympic的索引';
        echo '
';
        echo '
';
    }
    else
    {
        echo $c.'不是数组olympic的索引';
        echo '
';
        echo '
';
    }
}
?>

输出:
Rome不是数组olympic的索引
Athens是数组olympic的索引
Shanghai不是数组olympic的索引



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template