我知道如何在一個數組中設置PHP cookie,但是我可以在沒有循環的情況下清除它嗎?
比如我設置這四個餅乾清除PHP餅乾陣列
// set the cookies
setcookie("cookie[four]", "cookiefour");
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
setcookie("cookie[one]", "cookieone");
// after the page reloads, print them out
if (isset($_COOKIE['cookie'])) {
foreach ($_COOKIE['cookie'] as $name => $value) {
$name = htmlspecialchars($name);
$value = htmlspecialchars($value);
echo "$name : $value <br />\n";
}
}
OUTPUT:
四:cookiefour
三:cookiethree
二:cookietwo
之一:cookieone
要清除cookie,我使用fo循環播放
if (isset($_COOKIE['cookie'])) {
foreach ($_COOKIE['cookie'] as $name => $value) {
setcookie ("cookie[".$name."]", "", time() - 1);
}
}
有沒有什麼辦法可以清除沒有循環的cookie?在此先感謝
我認爲有像ClearAllCookies功能()的指標;在PHP中haha – DarkAmazon