小编mck*_*cky的帖子

PHP使用OR运算符检查多个值的值

我有一个文件名($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 = '';
}
Run Code Online (Sandbox Code Playgroud)

为什么带有OR运算符的if语句不起作用?

php comparison if-statement

5
推荐指数
1
解决办法
6338
查看次数

标签 统计

comparison ×1

if-statement ×1

php ×1