Ok, two arrays:
$first = array(1,2,3,4,5,6,7,8,9,10);
$second = array(1,2,3,4,5);
Is there a way (without looping through them if it can be helped) of doing an array_merge style function where it returns this array:
$new = array(6,7,8,9,10);
Where if it finds a match, it does not return it.
See array_diff()
$new = array_diff($first, $second);
print_r($new);
/*
Array
(
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
)
*/
array_diff()
should do this:
<?php
$array1 = array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);
print_r($result);
?>
Array
(
[1] => blue
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With