note 46098 added to function.array-search

From: Date: Wed, 29 Sep 2004 12:04:05 +0000
Subject: note 46098 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-77560@lists.php.net to get a copy of this message
There is no way to use this function to search an object in the array. I want to suggest my own function for this problem solve <?php /** $Id$ * Searches the array for a given object and returns the corresponding key if successful or FALSE otherwise */ function object_search($needle, $haystack, $strict=false) { if (!is_array($haystack)) return false; for ($i=0; $i<count($haystack); ++$i) { if ($strict) { // STRICT if ((get_class($needle)==get_class($haystack[$i])) && ($needle==$haystack[$i])) return $i; } else { // NO STRICT if ($needle==$haystack[$i]) return $i; } } return false; }// function object_search ?> ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46098 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46098&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46098&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77560) next »