php中有兩個函數(shù)用來判斷數(shù)組中是否包含指定的鍵,,分別是array_key_exists和isset
array_key_exists語法如下
array_key_exists($key, $array) |
如果鍵存在返回true isset函數(shù)語法如下
如果鍵存在返回true 演示代碼
<?php
$array = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java");
print("Is 'One' defined? ".array_key_exists("One", $array)."\n");
print("Is '1' defined? ".array_key_exists("1", $array)."\n");
print("Is 'Two' defined? ".isset($array["Two"])."\n");
print("Is '2' defined? ".isset($array[2])."\n");
?>
|
返回結(jié)果如下:
Is ‘One’ defined? 1
Is ’1′ defined?
Is ‘Two’ defined? 1
Is ’2′ defined? |
延伸閱讀:
|