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?
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?
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.
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
)