0
I have 2 arrays and need to make a comparison between them, to find what values are missing in the 2nd array ($arrayxml
), for example:
$arraybd=array('1','2','3','4');
$arrayxml=array('1','2');
In this case the values are missing '3'
and '4'
in $arrayxml
, then take these values '3'
and '4'
to be able to perform the task I need (I will remove it from the database).
The ideal would be to generate a string, or even an array with the values that are missing, in the above case, would be:
$valoresdiferentes=('3','4')
What’s the best way to do that?
show, what is the difference between the array_diff_assoc and diff?
– Leandro Marzullo
@Leandromarzullo a diff_assoc array_also includes the keys in the comparison, if only the values use the same diff array_example, if you have an array as follows $array("a" => "value1", "b" => "value2"); and another $array2 array("value1", "b" => "value2"); It will consider the "valor1" of array2 to be different because it does not have the key "a"
– Anderson Henrique