Answer the question
In order to leave comments, you need to log in
How to set COOKIE values, depending on availability?
Tell me what the function will look like.
If there is COOKIE_1, then var1 = COOKIE_1. If there is no COOKIE_1, then var1 = 0.
If there is COOKIE_2, then var1 = COOKIE_2.
Those. var1 needs to be changed depending on the presence of COOKIE.
Answer the question
In order to leave comments, you need to log in
Для версии php < 7
$var = isset($_COOKIE['cook_2']) ? $_COOKIE['cook_2'] : (isset($_COOKIE['cook_1']) ? $_COOKIE['cook_1'] : 0);
Для версии php >= 7
$var = $_COOKIE['cook_2'] ?? $_COOKIE['cook_1'] ?? 0;
Option 1:
if(isset($_COOKIES[2])) $var = $_COOKIES[2];
elseif(isset($_COOKIES[1])) $var = $_COOKIES[1];
else $_var = 0;
$var = isset($_COOKIES[2]) ? $_COOKIES[2] : (isset($_COOKIES[1]) ? $_COOKIES[1] : 0);
did not check anything, but I think it should work)) $var = $_COOKIES[2] ?? ($_COOKIES[1] ?? 0);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question