I have these two arrays that I need to compare to clear the differences.
Array1 which is equivalent to everything in mysql
Array(
[0] => Array
(
[id] => 133
[que] => Codigo
[idcosa] => 9
[1] => 36
[2] => 40
[3] => verde
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
[1] => Array
(
[id] => 134
[que] => Codigo
[idcosa] => 9
[1] => 37
[2] => 37
[3] => borrar
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
[2] => Array
(
[id] => 135
[que] => Codigo
[idcosa] => 9
[1] => 36
[2] => 37
[3] => colao
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
[3] => Array
(
[id] => 136
[que] => Codigo
[idcosa] => 9
[1] => 36
[2] => 70
[3] => Gris marengo
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
)
Array2 which is equivalent to what I have of a cartesian product of a form
Array (
[0] => Array
(
[0] => 133
[id] => 133
[1] => 36
[que] => Codigo
[2] => 40
[idcosa] => 9
[3] => verde
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
)
[1] => Array
(
[0] => 135
[id] => 135
[1] => 36
[que] => Codigo
[2] => 37
[idcosa] => 9
[3] => colao
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
)
[2] => Array
(
[0] => 136
[id] => 136
[1] => 36
[que] => Codigo
[2] => 70
[idcosa] => 9
[3] => Gris marengo
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
)
)
From what I see the cartesian product puts a new field in the array that is [0] that has the same number as [id]
If we compare the data, it should give me this result:
[1] => Array
(
[id] => 134
[que] => Codigo
[idcosa] => 9
[1] => 37
[2] => 37
[3] => borrar
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
But for some strange reason it doesn't give it to me and tells me that the result of the comparison is 0 or a wrong code.
I am comparing with this code $Diferencia = array_diff_assoc($array1,$array2);
and I have also tried with dry array_diff, looking at the php website in case there is any other comparator I have not seen anything else (well there are several but I think they do not fit me) is there any other way to do this? or do I have something wrong that I don't know?
The array_diff_assoc throws me this as a result:
Array (
[3] => Array
(
[id] => 136
[que] => Codigo
[idcosa] => 9
[1] => 36
[2] => 70
[3] => Gris marengo
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
)
But if you look at that id it is in both 1 and 2. It may be silly but it drives me crazy and I don't see it, let's see if someone who knows more about php than I do sees where I have the conflict :) thank you very much everyone in advance.
you could use
array_udiff
.For example:
Result:
show