由于逗号而导致Php逻辑语句synatx错误
有人能帮忙吗由于逗号而导致Php逻辑语句synatx错误,php,Php,有人能帮忙吗 <?php if(((count( $replies ) > 6) and (count( $replies ) <= 12)) and ($replyNumber == '3','4','5')) { ?> <execute code......> <?php } ?> 为什么由于使用逗号(在replynumber中为3,4,5)而导致代码中出现错误请按以下方式更改代码: <?php $varArray = ar
<?php
if(((count( $replies ) > 6) and
(count( $replies ) <= 12)) and
($replyNumber == '3','4','5'))
{ ?>
<execute code......>
<?php } ?>
为什么由于使用逗号(在replynumber中为3,4,5)而导致代码中出现错误请按以下方式更改代码:
<?php
$varArray = array('3','4','5');
if( ((count( $replies ) > 6) && (count( $replies ) <= 12)) && (in_array($replyNumber,$varArray)) ) { ?>
<execute code......>
<?php } ?>
您的代码中有错误
($replyNumber == '3','4','5'))
可能是
($replyNumber == '3' && $replyNumber == '4' && $replyNumber == '5'))
在代码中
'and'
应转换为
php中不允许使用'&&
作为'和'
完整的代码应该是这样的
<?php
if(((count( $replies ) > 6) &&
(count( $replies ) <= 12)) &&
($replyNumber == '3' && $replyNumber == '4' && $replyNumber == '5'))
{ ?>
<execute code......>
<?php } ?>
您有一个语法错误,是逗号的
和(您必须对$replyNumber
值使用或
)
注意:
&或
是|
或逻辑运算符
如果$x或$y为True,则为True
Ex:$x | |$y
如果$x或$y为True,则为True
&和
是&
和逻辑运算符
如果$x和$y都为真,则为真
Ex:
$x&&$y
如果$x和$y都为真,则为真我认为应该存在这样的或条件:$replyNumber=='3'| |$replyNumber=='4'是,使用带OR条件的Pritam解决方案有效。谢谢你们两位you@Ruchika…我认为你必须在计算两个值之后和之前使用和e$replyNumber??
<?php
if( ((count($replies)>6) or (count($replies)<=12)) and $replyNumber=='3' or $replyNumber=='4' or $replyNumber=='5' )
{
// your execute code here
}
?>