note 73542 added to language.oop5.object-comparison
| From: | rune at zedeler dot dk | Date: | Wed, 28 Feb 2007 16:34:08 +0000 |
| Subject: | note 73542 added to language.oop5.object-comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123955@lists.php.net to get a copy of this message | ||
Whoops, apparently I hadn't checked the array-part of the below very well.
Forgot to test if the arrays had same length, and had some misaligned parenthesis.
This one should work better :+)
<?
function deepCompare($a,$b) {
if(is_object($a) && is_object($b)) {
if(get_class($a)!=get_class($b))
return false;
foreach($a as $key => $val) {
if(!deepCompare($val,$b->$key))
return false;
}
return true;
}
else if(is_array($a) && is_array($b)) {
while(!is_null(key($a)) && !is_null(key($b))) {
if (key($a)!==key($b) || !deepCompare(current($a),current($b)))
return false;
next($a); next($b);
}
return is_null(key($a)) && is_null(key($b));
}
else
return $a===$b;
}
?>
----
Server IP: 82.103.133.188
Probable Submitter: 86.52.12.238
----
Manual Page -- http://www.php.net/manual/en/language.oop5.object-comparison.php
Edit -- https://master.php.net/note/edit/73542
Del: integrated -- https://master.php.net/note/delete/73542/integrated
Del: useless -- https://master.php.net/note/delete/73542/useless
Del: bad code -- https://master.php.net/note/delete/73542/bad+code
Del: spam -- https://master.php.net/note/delete/73542/spam
Del: non-english -- https://master.php.net/note/delete/73542/non-english
Del: in docs -- https://master.php.net/note/delete/73542/in+docs
Del: other reasons-- https://master.php.net/note/delete/73542
Reject -- https://master.php.net/note/reject/73542
Search -- https://master.php.net/manage/user-notes.php