是的,array_key_exists()
函數可以檢查字符串是否存在于數組中
<?php
$array = array("key1" => "value1", "key2" => "value2", "key3" => "value3");
$key = "key2";
if (array_key_exists($key, $array)) {
echo "The key '$key' exists in the array.";
} else {
echo "The key '$key' does not exist in the array.";
}
?>
在這個例子中,array_key_exists()
函數檢查 $key
是否存在于 $array
中。如果存在,它將輸出 “The key ‘key2’ exists in the array.”,否則輸出 “The key ‘key2’ does not exist in the array.”。