I have an array:
$countryList = array(
"GB" => "United Kingdom",
"US" => "United States",
"AF" => "Afghanistan",
"AL" => "Albania",
"DZ" => "Algeria"
);
and it goes on…
When I get a country location it comes out as, for example, United States, but I need to match that (the value) with the key, in this case ‘US’. How would I do this? All the examples I have seen had to do with using the key to get the value when I need to use the value to get the key. Optimally the output will be just ‘US’, rather than that in an array.
I have tried echo array_keys('United States', $countryList); but it wants the first parameter to be in an array and it only comes in as United States, and I rather not change that to an array if possible.
You can use
array_searchfunction: