note 77615 deleted from function.array-diff by googleguy

From: Date: Tue, 22 Oct 2013 08:00:37 +0000
Subject: note 77615 deleted from function.array-diff by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-196717@lists.php.net to get a copy of this message
Note Submitter: radim at badsi dot info ---- 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); ?>

« previous php.notes (#196717) next »