note 94009 added to function.array-diff

From: Date: Mon, 12 Oct 2009 07:13:03 +0000
Subject: note 94009 added to function.array-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-161643@lists.php.net to get a copy of this message
To build on "merlinyoda at dorproject dot net" comment from 28-Mar-2008 06:11. If you are dealing with associative arrays: Instead of array_intersect we use array_intersect_assoc and instead of array_diff we use array_diff_assoc. Looks like a no brainer but this left me stumped for quite a while. Also note that the order of the arrays when passed to array_merge and array_intersect_assoc are very important to the result. <?php function array_xor ($array_a, $array_b) { $union_array = array_merge($array_a, $array_b); $intersect_array = array_intersect_assoc($array_a, $array_b); return array_diff_assoc($union_array, $intersect_array) } ?> ---- Server IP: 203.211.135.122 Probable Submitter: 121.6.96.126 ---- Manual Page -- http://www.php.net/manual/en/function.array-diff.php Edit -- https://master.php.net/note/edit/94009 Del: integrated -- https://master.php.net/note/delete/94009/integrated Del: useless -- https://master.php.net/note/delete/94009/useless Del: bad code -- https://master.php.net/note/delete/94009/bad+code Del: spam -- https://master.php.net/note/delete/94009/spam Del: non-english -- https://master.php.net/note/delete/94009/non-english Del: in docs -- https://master.php.net/note/delete/94009/in+docs Del: other reasons-- https://master.php.net/note/delete/94009 Reject -- https://master.php.net/note/reject/94009 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161643) next »