note 94560 added to function.array-diff
| From: | Dougle at osu1 dot php dot net | Date: | Wed, 11 Nov 2009 23:47:31 +0000 |
| Subject: | note 94560 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162785@lists.php.net to get a copy of this message | ||
To reply to Anonymous' function:
<?php
function array_diff_ORG_NEW(&$org, &$new, $type='VALUES'){
switch($type){
case 'VALUES':
$int = array_values(array_intersect($org, $new)); //C = A ^ B
$org = array_values(array_diff($org, $int)); //A' = A - C
$new= array_values(array_diff($new, $int)); //B' = B - C
break;
case 'KEYS':
$int = array_values(array_intersect_key($org, $new)); //C = A ^ B
$org = array_values(array_diff_key($org, $int)); //A' = A - C
$new= array_values(array_diff_key($new, $int)); //B' = B - C
break;
}
}
?>
Why would the following not suffice? (for values)
<?php
$a = 1,2,3;
$b = 2,3,4; //supposing this is the "new" array
$a = array_diff($a,$b);
$b = array_diff($b,$a);
?>
----
Server IP: 92.48.74.199
Probable Submitter: 82.20.26.189
----
Manual Page -- http://www.php.net/manual/en/function.array-diff.php
Edit -- https://master.php.net/note/edit/94560
Del: integrated -- https://master.php.net/note/delete/94560/integrated
Del: useless -- https://master.php.net/note/delete/94560/useless
Del: bad code -- https://master.php.net/note/delete/94560/bad+code
Del: spam -- https://master.php.net/note/delete/94560/spam
Del: non-english -- https://master.php.net/note/delete/94560/non-english
Del: in docs -- https://master.php.net/note/delete/94560/in+docs
Del: other reasons-- https://master.php.net/note/delete/94560
Reject -- https://master.php.net/note/reject/94560
Search -- https://master.php.net/manage/user-notes.php