How can the use of explode() and array_key_exists() functions affect the retrieval of values from arrays in PHP?

When using the explode() function to split a string into an array, the keys of the resulting array are numeric. This can cause issues when trying to retrieve values using specific keys. To address this, you can use the array_key_exists() function to check if a key exists in the array before attempting to access its value.

// Example of using explode() and array_key_exists() to retrieve values from arrays in PHP

$string = "apple,banana,orange";
$array = explode(",", $string);

// Check if key exists before accessing the value
if(array_key_exists(1, $array)){
    $value = $array[1];
    echo $value; // Output: banana
} else {
    echo "Key does not exist";
}