Return duplicated values in arrays

Asked

Viewed 825 times

7

My question is this? I have the following array:

$array1 = array(10, 50, 80, 40, 90);
$array2 = array(10, 30, 10, 40, 20);
$array3 = array(10, 60, 15, 40, 30);
$array4 = array(20, 30, 40, 10, 50);
$array5 = array(10, 05, 10, 90, 40);

I wonder if there is a simple way to go through all and return only the values that repeat in all arrays.

To get duplicate values from the same array I’m using:

$unArray = array_unique( array_diff_assoc( $idCliArray, array_unique( $idCliArray ) ) )

Now I need to know how to take only what repeats itself in all.

1 answer

7


You can use the function array_intersect, example:

$array1 = array(10, 50, 80, 40, 90);
$array2 = array(10, 30, 10, 40, 20);
$array3 = array(10, 60, 15, 40, 30);
$array4 = array(20, 30, 40, 10, 50);
$array5 = array(10, 05, 10, 90, 40);

$values = array_intersect($array1,$array2,$array3,$array4,$array5);

IDEONE

  • 1

    Thanks, @abfurlan, that gave me a north

Browser other questions tagged

You are not signed in. Login or sign up in order to post.