I have an array that has countries:
array(
\'AF\'=>\'AFGHANISTAN\',
\'AL\'=>\'ALBANIA\',
\'DZ\'=>\'ALGERIA\',
\'AS\'=>\'AMERICAN SAMOA\',
);
Simply loop over the SECOND array, and fetch the values from the first. Vise versa seems unneeded inefficient indeed.
So:
$Arr1 = array(
'AF'=>'AFGHANISTAN',
'AL'=>'ALBANIA',
'DZ'=>'ALGERIA',
'AS'=>'AMERICAN SAMOA',
);
$Arr2 = array('AL', 'DZ');
$result = array();
foreach ($Arr2 as $cc){
if (isset($Arr1[$cc])){
$result[$cc] = $Arr1[$cc];
}
}
print_r($result);
I don't think that is inefficient.
Edit addition: If you are 100% sure the $Arr2 contains only codes that can be found in $Arr1, you can of course skip the isset() test.