Check for duplicate numbers between two php arrays [duplicate]

2

Hello, I have two arrays in php and I need to check if there is any number in array 1 that repeats with some number in array 2. I do not need the numbers, I just need to know if it repeats! How to do?

    
asked by anonymous 10.10.2016 / 13:29

2 answers

0

Using the array_intersect function of php :

<?php
$array1 = array("a" => "green", "red", "blue");
$array2 = array("b" => "green", "yellow", "red");
$result = array_intersect($array1, $array2);
print_r($result);
?>

In this case, it will return everything contained in the two arrays keeping its chaves :

Array
(
    [a] => green
    [0] => red
)

You can use or create another function that uses this method as it is best for your rule.

    
10.10.2016 / 13:35
0

You can use array_intersect

<?php

   $array1 = array("a" => "verde", "vermelho", "azul");
   $array2 = array("b" => "verde", "amarelo", "vermelho");
   $result = array_intersect($array1, $array2);
   print_r($result);

?>

Return:

Array
(
    [a] => verde
    [0] => vermelho
)
    
10.10.2016 / 13:34