如果$ _POST为空多功能 [英] If $_POST is empty Multiple function

查看:90
本文介绍了如果$ _POST为空多功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下$ _POST函数来检查'start','middle'和'end'的字段是否为空。

I have the following $_POST function to check if the fields of 'start', 'middle' and 'end' is empty or not.

if(!empty($_POST['start'])) {
   $description = "a sentence".$_POST['start']." with something in the START.";
}

if(!empty($_POST['middle'])) {
   $description = "a sentence".$_POST['middle']." with something in the MIDDLE.";
}

if(!empty($_POST['end'])) {
   $description .= "a sentence".$_POST['end']." with something in the END.";
}

我想检查一个函数中的值,换句话说我想要同时检查多个值。我看过很少的方法,但不确定哪一个是正确的,使用逗号&& || ,如下所示。 。

I want to check the values in one function, in other words I want to check multiple values at the same time. I have seen few method but not sure which one is right, using comma or && or ||, something like below ...

if(!empty($_POST['start']) , (!empty($_POST['middle']) , (!empty($_POST['end']))

if(!empty($_POST['start']) && (!empty($_POST['middle']) && (!empty($_POST['end']))

if(!empty($_POST['start']) || (!empty($_POST['middle']) || (!empty($_POST['end']))

任何人都可以告诉我这种正确的代码形成?

Can anyone tell me the right code for this kind of formation?

推荐答案

这里有一些基本的...我把它作为评论(因为我不确定这是不是你要求的东西)但我猜一个答案适合一些细节。

here are some basic.. i made it as a comment(as i was not sure if this is the thing you asked for) but i guess an answer would be appropriate with a bit of details.


  • AND operatior

&&将检查每个条件,如果一切都是真的,它将返回true ...

the && will check every condition and if all are true it will return true...

把它当作这个

if(FALSE && TRUE)

它将始终返回False,如果不执行,因为其中一个条件为false

it will always return False and if will not execute because one of the condition is false


  • OR运算符

THe ||将检查第一个条件,如果它的真实,它将返回true,否则检查第二个条件如果所有都是假(甚至没有一个是真的)它将返回false。

THe || will check the first condition if its true it will return true else check the second condition If all are false(not even a single is true) it will return false.

再次按照上一个例子

if(TRUE || False || False)

现在编译器检查第一个条件是否为真,它将忽略接下来的两个条件并返回true。

now the compiler checks the first condition if its true it will ignore the next two conditions and return true.

if(FALSE || FALSE || FALSE) - 这将返回false,因为所有都是假的

if(FALSE || FALSE || FALSE) - this will return false as all are false


  • 逗号运算符

如果你操作员然后将评估右边的最后一个条件,如果是,则返回true,否则返回false

if you , operatior then the last condition to the right will be evaluated and if it is true then it will return true else false

示例

if(True,True,True,False)  -  it will return false

if(FALSE, TRUE, FALSE, TRUE) - it will return true

因此请根据您的逻辑选择运算符。

so choose the operator according to your logic.

使用此:

if((!empty($_POST['start'])) && (!empty($_POST['start'])) && (!empty($_POST['start'])));

这篇关于如果$ _POST为空多功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆