The function array_key_exists()
is used to check whether the specified key exists in an array or not.
The function returns TRUE if the given key is set in the array. The key can be any possible value for the array index.
Syntax
array_key_exists(array_key, nama_array)
Parameter
| Nama | Keterangan | Wajib / Opsional | Jenis |
|------------|-----------------------------------------------------|------------------|-----------|
| array_key | Nilai untuk diperiksa. | Yg dibutuhkan | Campuran* |
| nama_array | Array yang ditentukan yang kuncinya akan diperiksa. | Yg dibutuhkan | Himpunan |
*Mixed: Mixed indicates that the parameter can accept multiple (but not necessarily all) types.
Return Value
TRUE on success or FALSE on failure.
Value Type: Boolean
Example
<?php
$array1=array("Orange" => 100, "Apple" => 200, "Banana" => 300, "Cherry" => 400);
if (array_key_exists("Banana",$array1))
{
echo "Array Key exists...";
}
else
{
echo "Array Key does not exist...";
}
?>