note 54531 deleted from function.array-keys by danbrown
| From: | danbrown@php.net | Date: | Wed, 25 Aug 2010 01:50:11 +0000 |
| Subject: | note 54531 deleted from function.array-keys by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172013@lists.php.net to get a copy of this message | ||
Note Submitter: cristianDOTzuddas [AT] gmailDOTcom
----
The function extracts the key of an associative array from the position you need.
Input:
$arr = array('a'=>'first', 'b'=>'second',
'c'=>'third');
print(array_key($arr, 1));
Output: 'b'
<?
function array_key($arr, $pos) {
if (!empty($arr)) {
if ($pos===null)
$pos = 0;
$all_keys = array_keys($arr);
unset($arr);
$key = $all_keys[$pos];
unset($all_keys);
if (isset($key))
return $key;
else {
unset($key);
return null;
}
}
}
?>