note 84059 added to function.array-keys
| From: | info at marc-gutt dot de | Date: | Thu, 26 Jun 2008 02:41:52 +0000 |
| Subject: | note 84059 added to function.array-keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140821@lists.php.net to get a copy of this message | ||
cristianDOTzuddas [AT] gmailDOTcom function has to be named "array_pos" not
"array_key". This one could be array_key.
Should only be used if $search_value is unique in $array (or it returns first found key).
function:
<?php
function array_key($array, $search_value)
{
return current(array_keys($array, $search_value));
}
?>
example:
<?php
$array = array('foot', 'bike', 'car', 'plane');
print_r($array);
$key = array_key($array, 'bike');
echo("\nKey\n" . $key);
?>
output:
Array
(
[0] => foot
[1] => bike
[2] => car
[3] => plane
)
Key
1
----
Server IP: 212.124.37.9
Probable Submitter: 84.63.117.114
----
Manual Page -- http://www.php.net/manual/en/function.array-keys.php
Edit -- https://master.php.net/note/edit/84059
Del: integrated -- https://master.php.net/note/delete/84059/integrated
Del: useless -- https://master.php.net/note/delete/84059/useless
Del: bad code -- https://master.php.net/note/delete/84059/bad+code
Del: spam -- https://master.php.net/note/delete/84059/spam
Del: non-english -- https://master.php.net/note/delete/84059/non-english
Del: in docs -- https://master.php.net/note/delete/84059/in+docs
Del: other reasons-- https://master.php.net/note/delete/84059
Reject -- https://master.php.net/note/reject/84059
Search -- https://master.php.net/manage/user-notes.php