check if a key exists in an array in PHP

check if a key exists in an array in PHP

In this post we will give you information about check if a key exists in an array in PHP. Hear we will give you detail about check if a key exists in an array in PHPAnd how to use it also give you demo for it if it is necessary.

Use the PHP array_key_exists() function


You can use the PHP array_key_exists() function to test whether a given key or index exists in an array or not. This function returns TRUE on success or FALSE on failure.


Let’s take a look at the following example to understand how it actually works:



<?php
$cities = array("France"=>"Paris", "India"=>"Mumbai", "UK"=>"London", "USA"=>"New York");
 
// Testing the key exists in the array or not
if(array_key_exists("France", $cities)){
    echo "The key 'France' is exists in the cities array";
}
?>


if you like then share it.

Hope this and post will helped you for implement check if a key exists in an array in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

  +  44  =  49

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US