note 108574 added to function.array-diff
| From: | psynnott at gmail dot com | Date: | Tue, 08 May 2012 10:01:25 +0000 |
| Subject: | note 108574 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187518@lists.php.net to get a copy of this message | ||
My task: Compare an array before and after an operation and be able to tell what was added and what
was deleted.
What I did: Read a ton of these comments and found several very convoluted solutions.
What I then did: Engage the brain and re-read the manual for array_diff()
What I came up with: 2 lines of functional code:
$before = array(1,2,3);
$after = array(2,4,5);
$toDelete = array_diff($before,$after);
$toAdd = array_diff($after,$before);
----
Server IP: 69.147.83.197
Probable Submitter: 212.118.224.149 (proxied: 62.255.164.28)
----
Manual Page -- http://www.php.net/manual/en/function.array-diff.php
Edit -- https://master.php.net/note/edit/108574
Del: integrated -- https://master.php.net/note/delete/108574/integrated
Del: useless -- https://master.php.net/note/delete/108574/useless
Del: bad code -- https://master.php.net/note/delete/108574/bad+code
Del: spam -- https://master.php.net/note/delete/108574/spam
Del: non-english -- https://master.php.net/note/delete/108574/non-english
Del: in docs -- https://master.php.net/note/delete/108574/in+docs
Del: other reasons-- https://master.php.net/note/delete/108574
Reject -- https://master.php.net/note/reject/108574
Search -- https://master.php.net/manage/user-notes.php