How can the issue of not being able to access the key directly from the caching value be resolved in PHP?

When caching values in PHP, the issue of not being able to access the key directly can be resolved by storing the key alongside the cached value in an associative array. This way, the key can be easily retrieved when needed.

// Store the key alongside the cached value
$cache = [
    'key1' => 'cached_value1',
    'key2' => 'cached_value2'
];

// Retrieve the cached value using the key
$key = 'key1';
$cachedValue = $cache[$key];
echo $cachedValue; // Output: cached_value1