仅三元运算符 运行 条件的第一部分

Ternary operator only running first part of condition

我无法使计数条件起作用。目前无论我上传一个还是多个文件,第一个条件"Multiple files were"是运行ning。第二部分永远不会运行ning.

如果只上传了一个文件,我还需要做些什么才能使条件的第二部分达到 运行?

$fu = new fileUpload();
$filename = $fu->upload();
$out = (count($filename) ? 'Multiple files were' : 'A file was'). '  uploaded. You can download ' . (count($filename) ? 'them' : 'the file'). ' from:</ul>';

你的逻辑有问题。

count($filename) 如果它是 0 以外的任何值,则解析为 truthy。

因此无论是 1 个文件还是 64 个文件,第一部分始终解析为 true。您需要:

count($filename) > 1 ?