note 97600 deleted from function.array-search by danbrown

From: Date: Tue, 27 Apr 2010 17:00:22 +0000
Subject: note 97600 deleted from function.array-search by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168730@lists.php.net to get a copy of this message
Note Submitter: fortierj at cogeco dot ca ---- Mrjay42, you are assuming that your associative array's keys are integers. You can simplify your function, and it will work just the same without the counters. It's also important to return a false if you couldn't find a key, as your function may return a result that could be interpreted as false (like 0). So just use it with === operator, or !== operator. function array_key_search($needle, $haystack){ foreach($haystack as $key => $value){ if($key == $needle){ return $key; } } return false; } Thanks...

« previous php.notes (#168730) next »