Say I have a cookie FOO
. The method I am using to clear the cookie currently is
if (isset($_COOKIE["FOO"])) {
unset($_COOKIE["FOO"];
setcookie("FOO", "", time() - 3600, "/"); // Essentially "clear" the cookie
}
I unthinkingly copy-pasted from here. I realize the if
statement is not necessary (I could simply unset
and setcookie
without testing), but does the if
make it more efficient if FOO
is not set? In other words, if the cookie is not set, is it more efficient to "clear" it anyway, or test for if it exists and do nothing if it does not exist.