note 94560 deleted from function.array-diff by danbrown

From: Date: Wed, 11 Nov 2009 23:49:56 +0000
Subject: note 94560 deleted from function.array-diff by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162789@lists.php.net to get a copy of this message
Note Submitter: Dougle ---- 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); ?>

« previous php.notes (#162789) next »