setcookie没有使用$ value参数的字符串数组

I am trying to do this:

setCookie('visitor', array(0 => 'one', 1 => 'two'), time()+3600, COOKIEPATH, COOKIE_DOMAIN, false);

But I am unable to get it work. The php reference explains "$value as string[optional]" which (as far as my understanding goes) should accept an array of string as argument. Please help me achieve something similar to this or correct me if my understanding of the php reference ( string[optional] ) is wrong.

Here is the setcookie function declaration:

setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);

use serialize(array(0 => 'one', 1 => 'two')) instead.

Use unserialize() when retrieving the array again.

And no: If the php manual says that the functions wants a string... Then they mean a string. Not an array of strings.

Maybe you are fooled by the [optional]? The square brackets don't mean anything. The whole "[optional]" thing just means that the function can be called without this parameter.

If the setcookie() function did allow you to overload type, it would do so by passing the array into a loop. Since it doesn't support arrays, I'd use a foreach loop outside the function.

foreach (array(0 => 'one', 1 => 'two') as $key => $value) {
    setcookie('visitor[' . $key . ']', $value, time()+3600, COOKIEPATH, COOKIE_DOMAIN, false);
)

var_dump($_COOKIE);

This results in...

array(1) {
    ["visitor"]=>
    array(2) {
        [0]=>
        string(3) "one"
        [1]=>
        string(3) "two"
    }
}