note 99097 deleted from function.array-search by danbrown

From: Date: Fri, 30 Jul 2010 16:41:22 +0000
Subject: note 99097 deleted from function.array-search by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-171264@lists.php.net to get a copy of this message
Note Submitter: infinitev at hotmail dot com ---- if your looking for fast and simple to use array_search that can search both keys and values.. try mine :) static function key_value_array_search($value, $array, $is_key=FALSE) { $result = FALSE; if(!$is_key) $result = array_search($value, $array); else $result = (in_array($value, array_keys($array)) ? $array[$value] : FALSE); return $result; } hope this helps someone, some of the others seems well over complex :/ example: //test array $arr = array('fruit' => 'banana', 'number' => 5, 'sport' => 'football', 8 => 'numeric'); $result = key_value_array_search(5, $arr, FALSE); echo $result."\n\n"; $result = key_value_array_search('fruit', $arr, TRUE); echo $result; results: number banana regards, Sean.

« previous php.notes (#171264) next »