<?php
$array1 = array(1, 2, 3, 4);
$array2 = array(1, 2, 5, 6);
$array3 = array(1, 2, 6);
// The result should contain ONLY: 1 and 2. 6 is not in all 3 results
$result = array();
for ($i = 1; $i <= 3; $i++)
{
$array = 'array' . $i;
if (empty($result))
{
$result = ${$array};
}
else
{
$inBoth = array_intersect($result, ${$array});
//$notInBoth = array_diff($result, ${$array});
$result = array_diff($result, array_unique(array_merge($result, $inBoth)));
}
}
var_dump($result);
preferences:
52.26 ms | 402 KiB | 5 Q