note 84059 deleted from function.array-keys by danbrown

From: Date: Wed, 25 Aug 2010 01:45:45 +0000
Subject: note 84059 deleted from function.array-keys by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172002@lists.php.net to get a copy of this message
Note Submitter: info at marc-gutt dot de ---- 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

« previous php.notes (#172002) next »