如何做||三元体内的语句?
我现在所拥有的是:
$somevar = ($progress_date != ('0000-00-00 00:00:00' || '//'))?$progress_date:'NA';
并且它永远不会吐出$progress_date。它默认总是打印“NA”。
这样做并使用 less () 来分隔事物
$somevar = ($progress_date != '0000-00-00 00:00:00' || '//')?$progress_date:'NA';
使得 $progress_date 总是吐出,即使日期设置为一串 0 也是如此。
有没有办法使用三元语句来捕获空白日期和设置为 0 的日期,以便打印出“NA”?
What I have right now is:
$somevar = ($progress_date != ('0000-00-00 00:00:00' || '//'))?$progress_date:'NA';
and it doesn't ever spit out $progress_date. It defaults to always printing 'NA' instead.
Doing this and using fewer () to separate things
$somevar = ($progress_date != '0000-00-00 00:00:00' || '//')?$progress_date:'NA';
makes it so $progress_date always spits out, even when the date is set to a string of 0's.
Is there a way using a ternary statement to catch both blank dates and dates set to 0 so that 'NA" gets printed out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来您真正想要的是一对带有
&&
的条件。每个布尔比较需要有两侧,因此您不能这样做:
而是在两侧进行完整比较。大声读出,它符合您的需要:进度日期不等于 thing1,进度日期也不等于 thing2
Looks like what you actually want is a pair of conditions with
&&
.You need to have two sides to each boolean comparison, so you cannot do :
Instead make the full comparison on both sides. Read out loud, it makes sense as what you need: Progress date is not equal to thing1 and progress date is also not equal to thing2
您没有正确使用 或 。
You're not using the or properly.
我认为它应该是
||
不能按您的预期使用,因为它总是评估为布尔值。这样$progress_date != ('0000-00-00 00:00:00' || '//')
实际上与以下内容相同:I think it should be
||
can't be used as you expected, because it always evaluates as boolean. That way$progress_date != ('0000-00-00 00:00:00' || '//')
is effectively the same as: