I would like to combine two arrays with each other:
$filtered = array(1 => 'a', 3 => 'c'); $changed = array(2 => 'b*', 3 => 'c*');
While merging should include all $filtered elements and all those $changed elements that have the corresponding key in $filtered :
$merged = array(1 => 'a', 3 => 'c*');
array_merge($filtered, $changed) will add additional $changed keys to $filtered . So it really does not fit.
I know that I can use $keys = array_intersect_key($filtered, $changed) to get the keys that exist in both arrays that are already part of the job.
However, I am wondering if there is any (native) function that can reduce the $changed array to an array with $keys specified by array_intersect_key ? I know that I can use array_filter with a callback function and check $keys for it, but is there probably some other purely native function to extract only those elements from the array from which keys can be specified?
I ask because native functions are often much faster than array_filter with a callback.
hakre source share