note 25640 added to function.in-array

From: Date: Tue, 01 Oct 2002 10:17:33 +0000
Subject: note 25640 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-37460@lists.php.net to get a copy of this message
I had a HUGE problem of comparing references to see if they were pointing to the same object. I ended up using this code! function in_o_array (&$needle, &$haystack) { if (!is_array($haystack)) return false; foreach ($haystack as $key => $val) { if (check_refs($needle, $haystack[$key])) return true; } return false; } function check_refs(&$a, &$b) { $tmp = uniqid(""); $a->$tmp = true; $bResult = !empty($b->$tmp); unset($a->$tmp); return $bResult; } Hope this helps someone have a more productive morning that me! :P -- http://www.php.net/manual/en/function.in-array.php http://master.php.net/manage/user-notes.php?action=edit+25640 http://master.php.net/manage/user-notes.php?action=delete+25640 http://master.php.net/manage/user-notes.php?action=reject+25640

« previous php.notes (#37460) next »