Req #64854 [Opn->Wfx]: array_key_exists( array('key1', 'key2', 'key3'), $array);
| From: | nikic@php.net | Date: | Thu, 16 May 2013 10:49:05 +0000 |
| Subject: | Req #64854 [Opn->Wfx]: array_key_exists( array('key1', 'key2', 'key3'), $array); | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-178966@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64854&edit=1
ID: 64854
Updated by: nikic@php.net
Reported by: bensor987 at neuf dot fr
Summary: array_key_exists( array('key1', 'key2', 'key3'),
$array);
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Arrays related
Operating System: All
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
For "normal" arrays (with no odd null-value usages), you can just use isset for this. E.g.
isset($_GET['foo'], $_GET['bar'], $_GET['baz']).
I think accepting an array for array_key_exists is not very clear, because it could mean either
"one of the keys exists" or "all of the keys exist".
Marking as Wfx, unless some clearer examples for use cases come up ;)
Previous Comments:
------------------------------------------------------------------------
[2013-05-16 07:44:48] bensor987 at neuf dot fr
Description:
------------
Why can't we give an array as the first parameter of array_key_exists() ? I have a few cases
where it would be useful. Especially when checking $_POST, $_GET or $_REQUEST arrays (for instance).
Test script:
---------------
$array_to_test = array( 'key1' => 1, 'key2' => 1, 'key3' => 1
);
$array_keys = array( 'key1', 'key2', 'key3');
var_dump( array_key_exists( $array_keys, $array_to_test ) );
var_dump( (array_key_exists( 'key1', $array_to_test ) && array_key_exists(
'key2', $array_to_test ) && array_key_exists( 'key3', $array_to_test ))
);// The same as above, but much longer.
Expected result:
----------------
bool(true) bool(true)
Actual result:
--------------
bool(false) bool(true)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64854&edit=1