php数组(八) array_key_exists
array_key_exists 检查数组里是否有指定的键名或索引。返回值为true或false
数组里有键 key 时,array_key_exists() 返回 true。 key 可以是任何能作为数组索引的值。
1、示例
<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
echo "The 'first' element is in the array";
}
?>
返回:
The 'first' element is in the array
2、array_key_exists与isset的区别,isset值为空的key 返回false
<?php
$search_array = array('first' => null, 'second' => 4);
// returns false
echo isset($search_array['first']) . "\n";
// returns true
echo array_key_exists('first', $search_array);
?>
posted on 2021-08-03 21:23 1450811640 阅读(116) 评论(0) 收藏 举报
浙公网安备 33010602011771号