Skip to content
PHP Logo

How can the count of existing cookies be accurately determined in PHP?

To accurately determine the count of existing cookies in PHP, you can use the `count` function along with the `$_COOKIE` superglobal array. This function will return the number of elements in an array, which in this case will be the number of cookies set.

php
// Count the number of existing cookies
$cookieCount = count($_COOKIE);

// Output the count of cookies
echo "Number of cookies set: " . $cookieCount;