you can check the existance of a variable with isset()
function like this :
if(isset($_COOKIE['data']) && is_array($_COOKIE['data']){
echo "data present";
} else{
echo "data is not present";
}
you can also check if a variable exist and not empty with empty()
function like this :
if(!empty($_COOKIE['data']) && is_array($_COOKIE['data']){
echo "data present and it's not empty";
} else{
echo "data is not present";
}
empty values are : null, "", 0, "0", 0.0, false, [], $var// undeclared var
also i see that your storing an array in the cookie, i suggest for best practice serializing the array before storing in a cookie like this :
setcookie('data', serialize($data), time()+3600);
to get it's value all you have to do is :
$data = !empty($_COOKIE['data']) ? unserialize($_COOKIE['data']) : null;