1.

Which array function checks if the particular key exists in the array?

Answer»

In PHP arrays, the array_key_exists() FUNCTION is used when the USER wants to check if a specific key is present INSIDE an array. If the function returns with a TRUE VALUE, it is present.

Here’s its syntax: array_key_exists(array_key, array_name)

Also, here is an example of how it works

Example

$array1 = array("Orange" => 100, "Apple" => 200, "Grapes" => 300, "Cherry" => 400);
if (array_key_exists("Grapes",$array1))
{
echo "Key exists";
}
else
{
echo "Key does not exist";
}

Output:

key exists



Discussion

No Comment Found