I have two arrays:
$array1 = array(1,2,3,4);
$array2 = array(1,2,3,4,5,6,7);
How can I remove the matched values from the arrays and display the remaining values?
I have two arrays:
$array1 = array(1,2,3,4);
$array2 = array(1,2,3,4,5,6,7);
How can I remove the matched values from the arrays and display the remaining values?
You should use array_diff
<?php
$array1 =array(1,2,3,4);
$array2 = array(1,2,3,4,5,6,7);
print_r(array_values(array_diff($array2,$array1)));
OUTPUT :
Array
(
[0] => 5
[1] => 6
[2] => 7
)
Try this:
You can use array_diif() function to get those values.
$A = array(1,2,3,4,5,6,7);
$B = array(1,2,3,4);
$C = array_intersect($A,$B); //equals (1,2,3,4)
$D = array_diff($A,$B); //equals (5,6,7)