Skip to content

Instantly share code, notes, and snippets.

@boscho87
Last active June 13, 2018 21:06
Show Gist options
  • Save boscho87/8eab30158596ed91e91acff560b3667a to your computer and use it in GitHub Desktop.
Save boscho87/8eab30158596ed91e91acff560b3667a to your computer and use it in GitHub Desktop.
Code for Thomas Chessa McSnake
<?php
$bucketOne = ['yellow', 'red', 'blue'];
$bucketTwo = ['yellow', 'yellow', 'red', 'blue', 'blue'];
//filter the second array so that there are only duplicated values in there
$values = array_filter(array_count_values($bucketTwo),function ($value) {
// > one means in the bucket it must appear at least 2 times, you can check for `$value == 2` if you only what elemnts that apprears twice and not more
if ($value > 1) {
return $value;
}
});
//remove all arrays from bucket one those ar not in the filtered bucketTwo
$output = array_intersect($bucketOne,array_keys($values));
var_dump($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment