3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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);
Output for 4.3.0 - 7.1.0
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(6) }