note 46098 deleted from function.array-search by danbrown
| From: | danbrown@php.net | Date: | Wed, 29 Apr 2009 13:05:59 +0000 |
| Subject: | note 46098 deleted from function.array-search by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153994@lists.php.net to get a copy of this message | ||
Note Submitter: voituk on asg dot kiev dot ua
----
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
?>