note 35252 modified in function.in-array by didou
| From: | didou@php.net | Date: | Mon, 25 Aug 2003 18:34:58 +0000 |
| Subject: | note 35252 modified in function.in-array by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55049@lists.php.net to get a copy of this message | ||
[editor note : you can also use array_keys()
didou]
To search thru the keys instead of the values, use the built-in function "array_flip"
instead of writing your own code.
Example (untested):
<?php
$var = array (
"Bob" => "Jones",
"Silvia" => "Allen",
"Stupid" => "Head"
);
$var = array_flip ($var);
$result = in_array("Bob", $var, TRUE);
?>
$result should be TRUE
--was--
To search thru the keys instead of the values, use the built-in function "array_flip"
instead of writing your own code.
Example (untested):
<?php
$var = array (
"Bob" => "Jones",
"Silvia" => "Allen",
"Stupid" => "Head"
);
$var = array_flip ($var);
$result = in_array("Bob", $var, TRUE);
?>
$result should be TRUE
http://www.php.net/manual/en/function.in-array.php