<?php
$array1 = ['keepThis', 'remove', false, 'keep', 'save', 'delete', 'extra'];
$array2 = ['hangOnto', 'remove', null, 'retain', 'keep', 'delete'];
$clean1 = $array1;
$clean2 = array_diff_ukey(
$array2,
$array1,
// Need to have "&" so the values get set.
function($a, $b) use (&$clean1, $array1, $array2) {
// Use isset() just in case keys are not identical
// or arrays are not the same length.
if (isset($array2[$b]) && $array2[$b] === $array1[$b]) {
unset($clean1[$b]);
}
return strcmp($array2[$a], $array1[$b]);
});
print_r($clean1);
print_r($clean2);
Deprecated: strcmp(): Passing null to parameter #1 ($string1) of type string is deprecated in /in/np0ag on line 20
Deprecated: strcmp(): Passing null to parameter #1 ($string1) of type string is deprecated in /in/np0ag on line 20
Deprecated: strcmp(): Passing null to parameter #1 ($string1) of type string is deprecated in /in/np0ag on line 20
Array
(
[0] => keepThis
[2] =>
[3] => keep
[4] => save
[6] => extra
)
Array
(
[0] => hangOnto
[3] => retain
)