|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63286 in_array returns false on the $_COOKIE array when the cookie name exists
Submitted: 2012-10-16 08:32 UTC Modified: 2012-10-16 09:23 UTC
From: pascal at niele dot nl Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
11 + 50 = ?
Subscribe to this entry?

 [2012-10-16 08:32 UTC] pascal at niele dot nl
From manual page:

The in_array($cookieName, $_COOKIE) always returns false even if the $cookieName exists in the $_COOKIE array

Test script:
When checking if a cookie exist, the in_array() does not work on the $_COOKIE array, you should isset() to check if the cookie exists.

 * part 1, setting cookie
$name = 'testCookie';
$value = 'testValue';
$expires = time() + (60 * 60 * 24 * 365);
$path = '/';

setcookie($name, $value, $expires, $path);

 * part 2, retrieving cookie
// output: array(1) { ["testCookie"] => string(9) "testValue" }

// output: bool(true)

var_dump(in_array($name, $_COOKIE)); // does not work as aspected !!!
// ouput: bool(false)

echo $_COOKIE[$name];
// output: testValue

Expected result:
return true on the in_array($cookieName, $_COOKIE) if the $cookieName exists in the $_COOKIE array


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-16 09:23 UTC]
-Status: Open +Status: Not a bug
 [2012-10-16 09:23 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

in_array is searching a value, not a key.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 10:01:24 2020 UTC