$arr1 = array('potato'=>1,'tomato'=>2,'apple'=>5,'banana'=>10);
$arr2 = array('orange'=>20,'tomato'=>3,'apple'=>5,'banana'=>20);
I need function that would return array(‘tomato’,’banana’), consider that it omits keys that don’t exist in one or the other array. Apple has the same value in both arrays, so it should be omitted – returned should be only keys whose values differ and are set
This should work (demo):
Output:
Reference:
array_intersect_key— Computes the intersection of arrays using keys for comparisonarray_diff— Computes the difference of arraysarray_keys— Return all the keys or a subset of the keys of an array