note 77615 added to function.array-diff
| From: | radim at badsi dot info | Date: | Wed, 05 Sep 2007 21:03:53 +0000 |
| Subject: | note 77615 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130228@lists.php.net to get a copy of this message | ||
array_diff doesn't work with arrays of objects because it compares the string-represantation of
the arguments (which is always "Object" for an object).
Here is an easy way to compute the difference of two arrays of objects :
<?php
...
function array_obj_diff ($array1, $array2) {
foreach ($array1 as $key => $value) {
$array1[$key] = serialize ($value);
}
foreach ($array2 as $key => $value) {
$array2[$key] = serialize ($value);
}
$array_diff = array_diff ($array1, $array2);
foreach ($array_diff as $key => $value) {
$array_diff[$key] = unserialize ($value);
}
return $array_diff;
}
array_obj_diff ($ao1, $ao2);
?>
----
Server IP: 217.174.196.197
Probable Submitter: 82.231.24.233
----
Manual Page -- http://www.php.net/manual/en/function.array-diff.php
Edit -- https://master.php.net/note/edit/77615
Del: integrated -- https://master.php.net/note/delete/77615/integrated
Del: useless -- https://master.php.net/note/delete/77615/useless
Del: bad code -- https://master.php.net/note/delete/77615/bad+code
Del: spam -- https://master.php.net/note/delete/77615/spam
Del: non-english -- https://master.php.net/note/delete/77615/non-english
Del: in docs -- https://master.php.net/note/delete/77615/in+docs
Del: other reasons-- https://master.php.net/note/delete/77615
Reject -- https://master.php.net/note/reject/77615
Search -- https://master.php.net/manage/user-notes.php