I'm using this code to display a list of the names of all cookies (not values):
foreach ($cookies as $key=>$item){
if (is_numeric($key)) {
echo "$key,";
}
}
That is working correctly. But, I'm trying to assign the full results to a variable that can be used later on in my code. I just need it to be a list of the cookie names, separated by a comma.
I tried turning it into a function and assigning it to a variable like this:
$cookies = $_COOKIE;
function get_cookies() {
foreach ($cookies as $key=>$item){
if (is_numeric($key)) {
return "$key,";
}
}
}
$all_cookies = get_cookies();
echo $all_cookies;
But when I do that, I'm getting this error:
Warning: Invalid argument supplied for foreach()
What exactly am I doing wrong?