Created
May 15, 2022 13:41
-
-
Save ricardoboss/0b1129ee32ba7d0d7862fb9806b53c4e 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 foo(array ...$as): array | |
{ | |
assert(count($as) >= 2); | |
return array_diff_uassoc(array_shift($as), ...$as, fn($a, $b) => $a - $b); | |
} |
True! Thanks for the suggestion!
Or call it repeatedly, each time with two arrays from $as. Could even use array_reduce for that:
function foo(array ...$as): array
{
assert(count($as) >= 2);
return array_reduce(
array_slice($as, 1, null, true),
fn($carry, $item) => array_diff_uassoc($carry, $item, fn($a, $b) => $a <=> $b),
$as[0]
);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could do this: