Is there any better way开发者_如何学C of redefining this if()
, what i dislike about this statement is $prefix
is repeated again and again and it looks ugly to me.
if($prefix == 'RSVH' ||
$prefix == 'RSAP' ||
$prefix == 'CMOS' ||
$prefix == 'CMSR' ||
$prefix == 'CMKS' ||
$prefix == 'CMWH' ||
$prefix == 'CMBL' ||
$prefix == 'LNRS' ||
$prefix == 'LNCM' ||
$prefix == 'LNMX' ||
$prefix == 'PMNG');
thank you..
You could use an array and the function in_array():
$values = array('RSVH', 'RSAP', 'CMOS' /*, ... */);
if ( in_array($prefix, $values) )
{
/* do something */
}
Probably I would use in_array()
if (in_array($prefix, array('RSVH','RSAP','CMOS'.....))
{
// It's in there...
}
精彩评论