PHP Array, get the key based on a value

If I have this array

$england = array(
        'AVN' => 'Avon',
        'BDF' => 'Bedfordshire',
        'BRK' => 'Berkshire',
        'BKM' => 'Buckinghamshire',
        'CAM' => 'Cambridgeshire',
        'CHS' => 'Cheshire'
);

I want to be able to get the three letter code from the full text version, how would i write the following function:

$text_input = 'Cambridgeshire';
function get_area_code($text_input){
    //cross reference array here
    //fish out the KEY, in this case 'CAM'
    return $area_code;
}

thanks!

8
задан Haroldo 2 December 2010 в 11:45
поделиться