I've got an array that looks like this:
$foo = array(
0 => array('a', 'b', 'c', 'd'),
1 => array('b', 'c', 'd'),
2 => array('b', 'd', 'f')
)
I'll refer to $foo[0], $foo[1], and $foo[2] as sub-arrays.
I basically need to perform an array_intersect() across all 3 sub-arrays in $foo. The result should be:
array('b', 'd')
As all three sub-arrays had these values in common. What is the best way to do this?
Some considerations:
- There will always be at least one sub-array. No upper limit.
- If only one sub-array is provided, it should return that sub-array
- If there aren't any common values in all the sub-arrays, an empty array should be returned
- If this functionality already exists as a PHP function, I will /facepalm