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'的键名。

也可以检查 数字索引。

原文地址:https://www.cnblogs.com/sweetXiaoma/p/6004195.html