我有一个文件名($fname
),需要给文件类型分配$pClass
,并在后面添加“-”。目前无论文件类型是什么,我都会得到text-
。
//This gets the extention for the file and assigns the class to the icon <i>
$pieces = explode('.', $fname);
$ext = array_pop($pieces);
if($ext == (('txt')||('rtf')||('log')||('docx'))){
$pClass = 'text-';
}
else if($ext == (('zip')||('sitx')||('7z')||('rar')||('gz'))){
$pClass = 'archive-';
}
else if($ext == (('php')||('css')||('html')||('c')||('cs')||('java')||('js')||('xml')||('htm')||('asp'))){
$pClass = 'code-';
}
else if($ext == (('png')||('bmp')||('dds')||('gif')||('jpg')||('psd')||('pspimage')||('tga')||('svg'))){
$pClass = 'image-';
}
else {
$pClass = '';
}
为什么我的带有OR运算符的if语句不起作用?
if
语句将始终返回true,这就是为什么你总是得到test-
的原因。 - mferly