Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多个“如果”条件_Php_If Statement - Fatal编程技术网

Php 多个“如果”条件

Php 多个“如果”条件,php,if-statement,Php,If Statement,我得到了这段代码,它为我的博客的每篇文章中有多少评论提供了标题 $pego_comment_caption = " Comments"; if (get_comments_number($post->ID) == 1) { $pego_comment_caption = " Comment"; } 因为我是一个语法纳粹分子,对PHP的理解远远不够,所以0注释实际上在图形上是不正确的,因为0小于1,并且。。嗯,你知道 我想更改if条件,使其在有0或1条注释时显示单词Comment

我得到了这段代码,它为我的博客的每篇文章中有多少评论提供了标题

$pego_comment_caption = " Comments";

if (get_comments_number($post->ID) == 1) {
    $pego_comment_caption = " Comment";
}
因为我是一个语法纳粹分子,对PHP的理解远远不够,所以0注释实际上在图形上是不正确的,因为0小于1,并且。。嗯,你知道


我想更改if条件,使其在有0或1条注释时显示单词Comment而不是Comments。这可能很简单,但我做不到。有人知道怎么做吗

只需在条件中添加or。在PHP中,布尔语句中或的符号为| | while和&

或者,您可以将其设置为任何小于1的值都可以进入此项,然后您可以:
如果get_comments_number$post->ID可以使用三元运算符

只需检查get_comments_number是否大于1,则为comments

像这样试试

$pego_comment_caption = (get_comments_number($post->ID) > 1 ? " Comments" : " Comment");

在你的陈述中替换这个

if (get_comments_number($post - > ID) <= 1) {
    $pego_comment_caption = " Comment";
}

一个真正的语法纳粹分子会知道0条评论实际上是正确的,但你根本不需要任何评论:如果get_Comments\u number$post->ID Zero不是某个东西中的一个,那么它就采用复数形式。某事物的分数也采用单数形式,它们被表示为“半个事物”或“一个事物的三分之二”,因此单数形式是合乎逻辑的,因为你提到了“一个事物”。不过你会说“0.5件事”。我刚刚发现在英语中0条评论在语法上是正确的,但问题是英语不是我的主要语言,而在我的母语葡萄牙语中它确实不正确。我只是翻译了评论部分,因为论坛是英文的,所以很简单马克,我试过了,但没用/我们可以在文字字符串中使用单引号吗:$pego\u comment\u caption=get\u comments\u number$post->ID>1评论':'评论';
$pego_comment_caption = (get_comments_number($post->ID) > 1 ? " Comments" : " Comment");
if (get_comments_number($post - > ID) <= 1) {
    $pego_comment_caption = " Comment";
}