php 刀片视图:带有 OR/AND 条件的 if 语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20841039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Blade view: if statement with OR/AND condition
提问by toesslab
Is it possible in Laravel 4.0-blade-view to do an if statment like so?
在Laravel 4.0-blade-view 中是否可以执行这样的 if 语句?
@if ($var1 === '1' OR $var2 === '1')
//Do my stuff
@endif
Or
或者
@if ($var1 === '1' || $var2 === '1')
//Do my stuff
@endif
Or whatever syntax it is. I didn't find anything in the L4 docs, does it exist ?
或者它是什么语法。我在 L4 文档中没有找到任何内容,它存在吗?
回答by JaTochNietDan
It should support all of your standard PHP operators, including || (logical OR).
它应该支持您所有的标准 PHP 运算符,包括 || (逻辑或)。
I have tested it myself and it works fine.
我自己测试过,效果很好。
Additionally, I would recommend simply testing this yourself in future to confirm it works/doesn't work.
此外,我建议您以后自己简单地测试一下,以确认它有效/无效。
回答by Arash Hatami
You can simply use and/ oroperators:
您可以简单地使用and/or运算符:
@if($a==1 and $b==2)
@if($a==1 or $b==2)

