note 70961 rejected from function.in-array by betz
| From: | betz@php.net | Date: | Tue, 07 Nov 2006 12:04:48 +0000 |
| Subject: | note 70961 rejected from function.in-array by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119463@lists.php.net to get a copy of this message | ||
Note Submitter: special at person dot com
----
I don't know if this is by design or not, but in_array() does not work with associative hashes:
<?php
$Test = Array("my_var" => 2);
print_r($Test);
echo "\n";
var_dump(in_array("my_var", $Test));
?>
Outputs:
Array
(
[my_var] => 2
)
bool(false)
The workaround is to use array_key_exists() instead:
<?php
$Test = Array("my_var" => 2);
print_r($Test);
echo "\n";
var_dump(array_key_exists("my_var", $Test));
?>
Outputs:
Array
(
[my_var] => 2
)
bool(true)