I have a foreach
loop that returns a variable number of arrays.
I need to run array_uintersect
between them with a custom function to find common elements, but array_uintersect
only accepts 3 parameters (2 arrays and the function).
This is what I have right now:
$all_freaktag_favorites = array();
foreach ($serie_preferite as $serie_preferita) {
$preferite_elements = pods('category', $serie_preferita['term_id']);
$freaktag_preferita = $preferite_elements->field('freaktag');
$all_freaktag_favorites[] = $freaktag_preferita;
}
function comparaFreaktag($tag1, $tag2) {
return strcmp($tag1['term_id'], $tag2['term_id']);
};
$common_freaktag_between_favorites = array_uintersect(
$all_freaktag_favorites[0],
$all_freaktag_favorites[1],
'comparaFreaktag'
);
This correctly returns me the intersection between the first 2 arrays in the loop, but I don't know how to do that with an undefined number of arrays.
Thanks!