note 59892 added to function.array-keys
| From: | (bitcetera.com) | Date: | Mon, 19 Dec 2005 14:43:57 +0000 |
| Subject: | note 59892 added to function.array-keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100414@lists.php.net to get a copy of this message | ||
Here's how to get the first key, the last key, the first value or the last value of a (hash)
array without explicitly copying nor altering the original array:
<?php
$array = array('first'=>'111', 'second'=>'222',
'third'=>'333');
// get the first key: returns 'first'
print array_shift(array_keys($array));
// get the last key: returns 'third'
print array_pop(array_keys($array));
// get the first value: returns '111'
print array_shift(array_values($array));
// get the last value: returns '333'
print array_pop(array_values($array));
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-keys.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59892
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59892&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59892&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59892&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59892&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59892&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59892&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59892&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59892&report=yes
Search -- http://master.php.net/manage/user-notes.php