note 54531 added to function.array-keys

From: Date: Thu, 07 Jul 2005 06:41:49 +0000
Subject: note 54531 added to function.array-keys
Groups: php.notes 
Request: Send a blank email to php-notes+get-91571@lists.php.net to get a copy of this message
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; } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.array-keys.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54531 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54531&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54531&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54531&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54531&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54531&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54531&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54531&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91571) next »