Well if you want to implode the values and store it in the cookie then you'd explode it to retrieve it as an array.
$array = array('orange', 'green', 'blue');
$string = implode(',', $array); // 'orange,green,blue'
$second_array = explode(',', $string); // array('orange', 'green', 'blue');
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
Well you did it in your example. All I did was explain the correct syntax for implode/explode. Also, see www.php.net/cookies
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
Thanks
but I am not sure on how to get the data back out of the cookie.
Then you didn't read the link I posted :)
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
If you know how to set and get data from the cookie I just gave you how to use implode/explode, just put them together. You already did the first part in your original post.
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
use serialize and unserialize instead of implode/explode
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
That is correct, you're not lost. You get
a:3:{s:5:"apple";s:5:"green";s:6:"orange";s:6:"orange";s:6:"banana";s:6:"yellow";}
from print serialize($data); and you get Array from echo $next
As a side note, don't mix echo and print, there's no reason to, they do the same thing.
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
heh, I guess I'm just not understand how you're not getting it. You can do 4 + 0 = 4 and you can do 0 + 4 = 4 but for some reason you can't do 2 + 2 = 4. You have the two pieces of the puzzle, you're just not putting them together.
Set the cookie
$some_array = array('Hello' => 'World');
setcookie('some_cookie', serialize($some_array), time() +3600);
Retrieve the cookie
$some_array = unserialize($_COOKIE['some_cookie']);
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268