Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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 - Fatal编程技术网

非常基本的PHP-如果和如果。。。?

非常基本的PHP-如果和如果。。。?,php,Php,我目前的代码如下: if ( ( $status == 'active' ) || ( $status == 'full' ) ) { 我还需要包括一个和声明。因此,如果$status是full或active,并且$position与“need photo”或“completed”匹配,则会显示。我如何包括和声明 我尝试了以下方法,但似乎不起作用: if ( ( $status == 'active' ) || ( $status == 'full' ) &&a

我目前的代码如下:

if ( ( $status == 'active' ) || 
     ( $status == 'full' ) ) {
我还需要包括一个和声明。因此,如果$status是full或active,并且$position与“need photo”或“completed”匹配,则会显示。我如何包括和声明

我尝试了以下方法,但似乎不起作用:

if ( ( $status == 'active' ) || 
     ( $status == 'full' ) && 
     ( $position == 'need photo' ) || 
     ( ( $position == 'completed' ) ) {

有什么帮助吗?谢谢!:-)我对这一切都不熟悉。我尝试了谷歌,但找不到明确的答案。

&&
的优先级高于
|
,因此您尝试的代码与以下代码相同:

if ($status == 'active' || ($status == 'full' && $position == 'need photo') || $position == 'completed') {
在简单的英语中,它的意思是,如果
状态
处于活动状态,或者
状态
已满,
位置
需要照片
,或者
位置
已完成

但是你想要:

if (($status == 'active' || $status == 'full') && ($position == 'need photo' || $position == 'completed')) {

这意味着,如果
状态
为活动状态或
状态
为完整状态,并且
位置
为需要照片或
位置
已完成

&
的优先级高于
位置
,则您尝试的代码与以下代码相同:

if ($status == 'active' || ($status == 'full' && $position == 'need photo') || $position == 'completed') {
在简单的英语中,它的意思是,如果
状态
处于活动状态
,或者
状态
已满,
位置
需要照片
,或者
位置
已完成

但是你想要:

if (($status == 'active' || $status == 'full') && ($position == 'need photo' || $position == 'completed')) {
这意味着,如果
状态
处于活动状态或
状态
处于满状态,并且
位置
需要照片
位置
已完成,则根据,因此,您需要用括号将
表达式分组:

if ( ($status == 'active || $status == 'full) && ($position == 'need photo' || $position == 'completed') ) {
    ...
根据,
优先于
,因此需要用括号将
表达式分组:

if ( ($status == 'active || $status == 'full) && ($position == 'need photo' || $position == 'completed') ) {
    ...

我想你只是缺少了一些括号。您需要的是
if((A)&&(B))
,其中A和B是复杂表达式(包含两个子表达式的表达式)

在您的例子中:A=
($status==“active”)| |($status==“full”)
和B=
($position==“need photo”)|($position==“completed”)

那么,试试这个:
if(***(**($status==“active”)| |($status==“full”)**(**($position==“need photo”)| |($position==“completed”)**){

我想你只是缺少了一些括号。你想要的是
if((A)和(B))
,其中A和B是复杂的表达式(一个包含两个子表达式的表达式)

在您的例子中:A=
($status==“active”)| |($status==“full”)
和B=
($position==“need photo”)|($position==“completed”)

那么,试试这个:
if(***(**($status==“active”)|($status==“full”)**(**($position==“need photo”)|($position==“completed”)**($position==“completed”)**){

太好了!太好了!太谢谢你了!**只是为了突出显示更改,不要把它们放在你的代码中:所以复制并通过这个:
if(($status==“active”)($status=='full')和($position=='need photo')| |($position=='completed')){
**只是为了突出显示更改,不要将它们放在代码中:所以复制并通过此:
如果(($status=='active')| |($status=='full'))和($position=='need photo')| |($position=='completed')){