我在 PHP 中有一个数组:
$wxCode = array(
'VC' => 'nearby',
'MI' => 'shallow',
'PR' => 'partial',
'BC' => 'patches of',
'DR' => 'low drifting',
'BL' => 'blowing',
'SH' => 'showers',
'TS' => 'thunderstorm',
'FZ' => 'freezing',
'DZ' => 'drizzle',
'RA' => 'rain',
'SN' => 'snow',
'SG' => 'snow grains',
'IC' => 'ice crystals',
'PE' => 'ice pellets',
'GR' => 'hail',
'GS' => 'small hail', // and/or snow pellets
'UP' => 'unknown',
'BR' => 'mist',
'FG' => 'fog',
'FU' => 'smoke',
'VA' => 'volcanic ash',
'DU' => 'widespread dust',
'SA' => 'sand',
'HZ' => 'haze',
'PY' => 'spray',
'PO' => 'well-developed dust/sand whirls',
'SQ' => 'squalls',
'FC' => 'funnel cloud, tornado, or waterspout',
'SS' => 'sandstorm/duststorm');
如果在这里,我有一点:
if (substr($part,0,1) == '-') {
$prefix = 'light ';
$part = substr($part,1);
}
elseif (substr($part,0,1) == '+') {
$prefix = 'heavy ';
$part = substr($part,1);
}
else $prefix = '';
但是,我想编写一个函数,根据数组和 if: light rain 将以下字符串:-RA 转换为以下文本。
我该怎么做?