note 12049 deleted from function.array-search by jimw

From: Date: Thu, 25 Oct 2001 23:14:43 +0000
Subject: note 12049 deleted from function.array-search by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-19445@lists.php.net to get a copy of this message
If you want one that will also work for an associative array, try this: function array_search ($needle, $haystack, $strict = FALSE) { foreach (array_keys($haystack) as $key) { if ($strict) { if ($haystack[$key] === $needle) return $key; } else { if ($haystack[$key] == $needle) return $key; } } return FALSE; } Note the function array_keys also has functionality for finding the key for a specified element.

« previous php.notes (#19445) next »