How to check if a key exists in an array in PHP
source link: https://www.laravelcode.com/post/how-to-check-if-a-key-exists-in-an-array-in-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to check if a key exists in an array in PHP
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.
Author : Harsukh Makwana
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK