I have two arrays:
$array1 = array('[param1]' ,'demo' ,'[param2]' ,'some' ,'[param3]');
$array2 = array('value1' ,'demo' ,'value2' ,'some' ,'value3');
I want to compare these two arrays and remove all duplicate values.
In the end, I want these two arrays but without ‘demo’ and ‘some’ values in them.
I want to remove all values from arrays that have the same index key and value.
Arrays will always have the same number of values and indexes, I only want to compare them and remove entries that have the same index key and value, from both of them.
I’m doing something like this now:
$clean1 = array();
$clean2 = array();
foreach($array1 as $key => $value)
{
if($value !== $array2[$key])
{
$clean1[$key] = $value;
$clean2[$key] = $array2[$key];
}
}
var_export($clean1);
echo "<br />";
var_export($clean2);
And this works! But I’m wondering is there any other way of doing this? Maybe without using foreach loop?
or you can do: