Check key exists in array PHP?

In this tutorial explain check key exists in array php. I explained easy step check if key exists in array php. you can easily understand of check key exists in array php.

we will use array_key_exists() function and isset() function to check key exists in array php. we will explain easily understand  examples are given.let’s see simple code example of check key exists in array php.

Example 1:
<?php

$myarray = [
    "id" => 1,
    "title" => "Solution",
    "description" => "This is best"
]

    if(array_key_exists("title",$myarray)) {
        echo("This key is exists.");
    }else {
        echo("This key is not exists.");
    };

?>
Output:
This key is exists.
Example 2:
<?php

$myarray = [
    "id" => 1,
    "title" => "Solution",
    "description" => "This is best"
];

    if(isset($myarray['title'])) {
        echo("This key is exists.");
    }else {
        echo("This key is not exists.");
    }
?>
Output:
This key is exists.

I hope this tutorial help you.

Leave a Reply

Your email address will not be published. Required fields are marked *