Get values of array that are 4 times duplicated

Hi all,

I hope I can explain my problem. I have 4 different arrays with numeric values (3, 7, 63 etc), but of course I could merge them into one. I need to check which values are present in each array (which values have 4 duplicates). I want to keep an array with all of the values that meet this requirement without duplicates.

I have found some ways to compare arrays, but I’m struggling with the fact that I have 4 arrays and that I’m not looking for ‘double’ duplicates but for ‘quadruple’ duplicates.

Who can send me in the right direction? Thanks!

Loop through your array and compare each value

This may not be the most efficient way but it gets the job done.


<?php $arrayOne = array(12,123,32,11,22); $arrayTwo = array(12,454,32,11,95); $arrayThree = array(12, 49,302,11,22); $arrayFour = array(12,34,32,22,11); $arrayHolder = array($arrayOne, $arrayTwo, $arrayThree, $arrayFour); $numberArray = array(); foreach($arrayHolder as $array){ foreach($array as $number){ if(!isset($numberArray[$number])){ $numberArray[$number] = array('count' => 1); } else { $numberArray[$number]['count'] = $numberArray[$number]['count'] + 1; } } } $newArray = array(); foreach($numberArray as $num => $val ){ $newArray[] = $num; } echo '

echo '
New Array:
'; print_r($newArray); echo '
'; ?>


Sponsor our Newsletter | Privacy Policy | Terms of Service