Source Code:
(back to article)
<?php // $array is an array variable $array = ["first" => "apple", "second" => "banana", "third" => "cherry"]; // $key is a string variable $key = "second"; // Checking if the specified key exists in the array using the isset() function if (isset($array[$key])) { // If the key exists, access the corresponding element in the array $value = $array[$key]; echo "The value of the key '$key' in the array is: $value"; } else { // If the key does not exist, display a message echo "The key '$key' does not exist in the array"; }
Result:
Report an issue