I am using a $_COOKIE[array] in order to save data for a single input. This input will only submit if the user entered the same value twice. For instance, if they submitted apple, then orange, then banana, then apple, the form would submit on the second appearance of “apple”.
I read [this tutorial](
http://phpprogramming.wordpress.com/2007/03/06/php-cookies-tutorial-and-examples/).
for ($i = 1; $i < 10; $i++) {
if (!isset($_COOKIE[$i])) {
setcookie("query" . [$i],$query,time()+604800,"/");
break1;
}
}
foreach ($_COOKIE["query"] as $key => $value) {
echo "$key:$value";
}
I believe it might be a syntax error since I get:
Warning: Invalid argument supplied for foreach()
If you know a better way (can’t be mySQL), then please let me know!
$_COOKIE[‘query’] can not store an array. This is also why you get an error when you try to use it in the foreach. You could serialize your array before saving it though. Something like this
also have a look at this post update cookie value in php for the expalanation why the urlencode / urldecode is used