I have an array that has countries:
array(
\'AF\'=>\'AFGHANISTAN\',
\'AL\'=>\'ALBANIA\',
\'DZ\'=>\'ALGERIA\',
\'AS\'=>\'AMERICAN SAMOA\',
);
I think this will help. Here is a function key_values_intersect that will work as you expected :)
$longcodes = array(
'AF' => 'AFGHANISTAN',
'AL' => 'ALBANIA',
'DZ' => 'ALGERIA',
'AS' => 'AMERICAN SAMOA',
);
$code = array('AL', 'DZ');
function key_values_intersect($haystack, $needle)
{
$tmp=array();
foreach ($needle AS $key) {
$tmp[$key] = $haystack[$key];
}
return $tmp;
}
print_r(key_values_intersect($longcodes,$code));