Skip to content

Instantly share code, notes, and snippets.

@hipsterjazzbo
Last active March 18, 2019 01:24
Show Gist options
  • Save hipsterjazzbo/b8a7fd4d7b8fb11add6556cdc879b613 to your computer and use it in GitHub Desktop.
Save hipsterjazzbo/b8a7fd4d7b8fb11add6556cdc879b613 to your computer and use it in GitHub Desktop.
Array intersect but good

PHP's array_intersect throws a fit if you only pass in one array cause it's a whiney baby. This one is good.

<?php
function array_intersect_good(array $arrays): array
{
if (count($arrays) === 1) {
return $arrays;
}
return array_intersect(...$arrays);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment