php中的常用数组函数(四)(数组中是否有某个键名或索引)

/***********array_key_exists(检查键名或索引是否在数组中)*****************/
$arr1 = array('name' => 'Sheldon', 'age' => 30, 'address' => 'Carlifornia');
if (array_key_exists('name', $arr1)) {
    echo 'the name element is in the array.';
} else {
    echo 'name elment not exist.';
}

查看$arr1中有没有叫'name'的键名。

也可以检查 数字索引。

posted on 2016-10-27 15:37  Sweet小马  阅读(481)  评论(0编辑  收藏  举报

导航