Answers for "if(key_exists("

PHP
8

php key exists

// Here's our fruity array
$fruits = ['apple', 'pear', 'banana'];

// Use it in an `if` statement
if (array_key_exists("banana", $fruits)) {
 // Do stuff because `banana` exists
}

// Store it for later use
$exists = array_key_exists("peach", $fruits);
Posted by: Guest on May-14-2020
0

Dictionary Check Key Exist

hh = {"a":3, "b":4, "c":5}

# check if a key exists

print("b" in hh)
# True
Posted by: Guest on December-10-2021

Browse Popular Code Answers by Language