PHP array_key_exists() 与array_keys() 函数使用方法与实例教程我们先来看看
array_key_exists()定义和用法
该array_key_exists ( )函数检查一个数组某一特定键,返回true ,如果存在的关键和虚假的关键是不存在。
语法
array_key_exists(key,array)
Parameter Description key Required. Specifies the key array Required. Specifies an array
提示和说明提示:请记住,如果您跳过的关键当您指定一个数组,一个整数产生的关键是开始,在0和1增加为每个价值。(见例 )
$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("a",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
输出结果.
Key exists!
再来看个实例吧.
$a=array("Dog",Cat");
if (array_key_exists(0,$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
输出结果.
Key exists!
好了下面我们来接着讲array_keys() 函数使用方法
定义和用法该array_keys ( )函数返回一个数组包含的钥匙。 语法 array_keys(array,value)
Parameter Description array Required. Specifies an array value Optional. You can specify a value, then only the keys with this value are returned strict Optional. Used with the value parameter. Possible values: true - Returns the keys with the specified value, depending on type: the number 5 is not the same as the string "5".false - Default value. Not depending on type, the number 5 is the same as the string "5".
来看个例子.
$a=array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
print_r(array_keys($a));
?>
输出结果.
Array ( [0] => a [1] => b [2] => c )
樱花校园模拟器4399中文版
樱花校园模拟器4399中文版,十分奇趣好玩的3d校园冒险模拟
我的暑假秘密回忆繁星新春版
我的暑假秘密回忆繁星新春版是一款少女模拟养成类休闲游戏。这款
樱花校园模拟器国际版
樱花校园模拟器国际版,一个超级自由超级好玩的自由恋爱模拟的游
饥荒海难九游版
饥荒海难九游版,带你去真实的海岛上感受一下什么才是真正的孤岛
盖瑞模组体验版最新版
盖瑞模组体验版是玩法非常丰富多元化的沙盒建造游戏,玩家可以在