如果我有这样的阵列PHP阵列,获得基于值的键
$england = array(
'AVN' => 'Avon',
'BDF' => 'Bedfordshire',
'BRK' => 'Berkshire',
'BKM' => 'Buckinghamshire',
'CAM' => 'Cambridgeshire',
'CHS' => 'Cheshire'
);
我希望能够从全文版本获得的三个字母代码,如何将我写了以下功能:
$text_input = 'Cambridgeshire';
function get_area_code($text_input){
//cross reference array here
//fish out the KEY, in this case 'CAM'
return $area_code;
}
谢谢!
+1 @Haroldo清楚,使用字符串时array_search是区分大小写的。 – SubniC 2010-12-02 11:50:28
是否有可能做array_seach,其中的值是一个正则表达式?然后,我可以使用preg_quote和帐户的缩写和不同版本的... ... – Haroldo 2010-12-02 11:54:51