How can we retrieve and decode a JSON-encoded array cookie in PHP?
To retrieve and decode a JSON-encoded array cookie in PHP, we first need to retrieve the cookie using the $_COOKIE superglobal, then use the json_decode function to decode the JSON string back into a PHP array. This allows us to access the values stored in the cookie as an array in our PHP code.
// Retrieve the JSON-encoded array cookie
$cookieValue = $_COOKIE['cookie_name'];
// Decode the JSON string into a PHP array
$decodedCookie = json_decode($cookieValue, true);
// Access the values in the array
foreach ($decodedCookie as $key => $value) {
echo $key . ': ' . $value . '<br>';
}