1
Good afternoon.
I would like to know how I can be comparing two arrays and keeping each pair of value found and print the numbers that were left without pair.
Ex: a) 1,2,3,4,5 b) 1,3,5,6,7,5,3
It would keep the pairs (1,1) (3,3) (5,5) and print the values 2,4,6,7,5,3 Note that 5 and 3 also have to be printed because not another that keeps the pair of the same.
I need to know exactly those values that have no pair, even if they are repeated. If anyone can shed some light, thank you.
Hugs
Thanks rray, exactly what I wanted.
– Gustavo Freire
@Gustavofreire if solved your problem can mark the answer as accepted, can see in => How and why to accept an answer?
– rray
Just one more question, he printed the values not found , but printed together, would it be possible to print the amounts of $a that are not in $b and $b that are not in $a, that separately? Thank you
– Gustavo Freire
@Gustavofreire call twice
array_diff()
solves the problem?$diffab = array_diff($a, $b);
$diffba = array_diff($b, $a);
see if this is it– rray
Printed only the numbers other than $a, in which case 8 was missing in $b $a = [1,2,3,4,5,7,7,9]; $b = [2,4,7,8,9]; EQUAL - Array ( [0] => (2, 2) [1] => (4, 4) [2] => (7, 7) [3] => (9, 9) ) DIFFERENT - Array& DIFFERENT - Array( [0] => 1 [1] => 3 [2] => 5 [3] => 7 )
– Gustavo Freire
@Gustavofreire the difference from b to a was in
$diffba
– rray
Yes, but can I print in two arrays the difference of each one? For example Array 1 = $diffab Array 2 = $diffba ? Because I need to take the numbers of each 1 add and then subtract Array 1 from Array 2.
– Gustavo Freire