I would like to compare two arrays excluding elements partially equal.
I have reached the following result:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
21 22 23 24 25
The desired result is:
21 22 23 24 25
$aa = array("1 2 3 4 5", "6 7 8 9 10", "11 12 13 14 15", "16 17 18 19 20", "21 22 23 24 25");
$bb = array("1 2", "6 7 8", "11 12 13 14", "16 17 18 19 20");
$final = array_diff($aa, $bb);
print_r($final)
You can use preg_grep in order to not have to do any manipulation the the data.
This will regex to see what is matching and then you just use array_diff.
$aa = array("1 2 3 4 5", "6 7 8 9 10", "11 12 13 14 15", "16 17 18 19 20", "21 22 23 24 25");
$bb = array("1 2", "6 7 8", "11 12 13 14", "16 17 18 19 20");
$exclude = [];
foreach($bb as $b){
$exclude = array_merge($exclude, preg_grep("/^". preg_quote($b) . "/", $aa));
}
$final = array_diff($aa, $exclude);
print_r($final);