Last active
June 13, 2018 21:06
-
-
Save boscho87/8eab30158596ed91e91acff560b3667a to your computer and use it in GitHub Desktop.
Code for Thomas Chessa McSnake
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 | |
$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