Created
March 29, 2017 08:35
-
-
Save smokills/46e1fc001d9f7607bbbc1104843ff8c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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