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.
Jasminkumar Borad
I'm a full-stack developer, enterpreneur and owner of webstuffsolution.com. I live in india and i like to write tutorial and tips that can help to other user. I like to share various programming language tips and solution. I believe in hardworking and consistency.