Checking If a Key Exists in an Array in PHP


Use array_key_exists() to check if a specific key is present in an array.

Source Code

$fruits = ['apple' => 'red', 'banana' => 'yellow'];
if (array_key_exists('apple', $fruits)) {
    echo "Apple exists in the array";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments