Delete registration of two arrays

-1

Good I have been looking for some function in php, that I remove data that are equal of an array and another example:

I have 2 arrays 1 with 3 records and another with 30, what I want to do is that if in those 3 the same thing is repeated in the second array, then I will remove it, or not show it to me and the result would be 27 records of the second array I do not know if you find something similar that can help me

    
asked by Juan Jose 17.11.2018 в 02:59
source

2 answers

0

Hi, I was checking and the array_diff () function may be helpful, look the php documentation array_diff ( array $array1 , array $array2 [, array $... ] ) compares two or more array and delivers an array of the values of the first array that are not in the other array you compared.

Another StackOverflow question may also be useful but in English that shows more functions to erase elements of arrays.

    
answered by 17.11.2018 в 03:40
0

Here you have two possible solutions to remove duplicates given two arrangements:

Option 1

$arreglo_nuevo = array_unique( array_merge($arreglo_1, $arreglo_1) );

Option 2

$arr_1 = array_diff($arr_1, $arr_2);
$arr_2 = array_diff($arr_2, $arr_1);

and if it gives you problems with the indices, that is to say that they do not follow the sequence 0,1,2,3, n + 1 ... use the following function and you will have it as you wish: D

array_values($arreglo);

References:

answered by 17.11.2018 в 17:31