for ($i = 0; $i < count($_COOKIE); $i++) 
                {
                     echo ($_COOKIE[$i]);
                }

Is there a reason this doenst work?

$_COOKIE is associative array. If you want to turn it to numerically indexed you can use array_values() function. But you are loosing valuable information. You can list values this way:

foreach($_COOKIE as $value) {

    echo $value;
}

Agree with broj1. Usually $_Cookie indexes are associative and use strings for the key names because the key name indicates what is stored at a location. Building off the example above, if you want even more details you can do

foreach($_COOKIE as $key => $value {
    echo '$_COOKIE["' . $key . '"] = ' . $value;
}

I perfer numeric and the values inside are

key -> vale

Nothing complicated AFAIK.

$_COOKIE is associative array. If you want to turn it to numerically indexed you can use array_values() function. But you are loosing valuable information. You can list values this way:

Ill try this.

I perfer using a normal for, not a foreach.

I perfer using a normal for, not a foreach.

Any reason for this?

Member Avatar for diafol

A normal 'for' assumes you know how many items you have in the array, doesn't it? I'd find it a pain to do that even if you do count() in normal circumstances where the index isn't important.

I'm with broj1 here wrt losing info with a returned indexed array. If you went to the trouble to give the cookie item a key, why not retrieve it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.