Skip to content

Instantly share code, notes, and snippets.

@smokills
Created March 29, 2017 08:35
Show Gist options
  • Save smokills/46e1fc001d9f7607bbbc1104843ff8c9 to your computer and use it in GitHub Desktop.
Save smokills/46e1fc001d9f7607bbbc1104843ff8c9 to your computer and use it in GitHub Desktop.
<?php
function array_variation($old, $new) {
$new_map = array_flip(array_values($new));
$old_map = array_flip(array_values($old));
return [
"added" => array_filter($new, function($e) use ($old_map) {
return !isset($old_map[$e]);
}),
"removed" => array_filter($old, function($e) use ($new_map) {
return !isset($new_map[$e]);
}),
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment