The difficulty here lies in that you compare key of one array with values of another one. E.g. by the use of array_diff_ukey.
Excerpt from PHP manual:
function key_compare_func($key1, $key2)
{
if ($key1 == $key2)
return 0;
else if ($key1 > $key2)
return 1;
else
return -1;
}
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
var_dump(array_diff_ukey($array1, $array2, 'key_compare_func'));
array(2) {
["red"]=>
int(2)
["purple"]=>
int(4)
}
Your second array is not associative, so this would compare "a" with 0, e.g.
So it's:
$compareFunc = function($key) uses ($a3) {
if(array_key_exists($key, $a3) {
return true;
}
else return false;
}
array_map($compareFunc, $a2);
can't be used neither, because this function is used to modify but not to reduce the array.
$a4 = array();
$compareFunc = function($key) uses ($a3, &$a4) {
if(array_key_exists($key, $a3) {
array_push($a4);
}
}
would do the job.
What I am trying to achieve is:
Play around with the PHP - functions that provide callbacks to you when the standart - functions don't succeed.
Try using the concept of binding, when the describtion of the callback doesn't fit your needs. With PHP's Lambda - functions you can bind objects / variables to a function,
so that you have access to variables that are not passed to the callback.
Get creative!!!