TWIG的 tests 学习_PHP教程
divisibleby null even odd sameas constant defined empty
divisibleby
检查是否能被整除
{% if loop.index is divisibleby(3) %}
...
{% endif %}
{% if loop.index is divisibleby(3) %}
...
{% endif %}
null
{{ var is null }}
{{ var is null }}
even
变量是否是偶数{{ var is even }}
{{ var is even }}
odd
变量是否是奇数
{{ var is odd }}{{ var is odd }}
sameas
检查变量的地址是否相同{% if foo.attribute is sameas(false) %}
the foo attribute really is the ``false`` PHP value
{% endif %}
{% if foo.attribute is sameas(false) %}
the foo attribute really is the ``false`` PHP value
{% endif %}
constant
检查变量的值是否相同{% if post.status is constant('Post::PUBLISHED') %}
the status attribute is exactly the same as Post::PUBLISHED
{% endif %}
{% if post.status is constant('Post::PUBLISHED') %}
the status attribute is exactly the same as Post::PUBLISHED
{% endif %}
defined
测试变量是否定义{# defined works with variable names #}
{% if foo is defined %}
...
{% endif %}
{# and attributes on variables names #}
{% if foo.bar is defined %}
...
{% endif %}
{% if foo['bar'] is defined %}
...
{% endif %}
{# defined works with variable names #}
{% if foo is defined %}
...
{% endif %}{# and attributes on variables names #}
{% if foo.bar is defined %}
...
{% endif %}{% if foo['bar'] is defined %}
...
{% endif %}
empty
测试变量是否为空,empty的意思是:该变量已经定义,但他的值是 null false 或者是空字符串
{# evaluates to true if the foo variable is null, false, or the empty string #}
{% if foo is empty %}
...
{% endif %}
摘自 jiaochangyun的专栏
上一篇: 求个正则 高难度的
推荐阅读
-
php实现计算百度地图坐标之间距离的方法,php坐标_PHP教程
-
Codeigniter 框架 Zip 编码类中 read_dir 方法的 bug_PHP教程
-
浅谈PHP中foreach/in_array的使用,foreachin_array_PHP教程
-
PHP实现上传文件并存进数据库的方法,_PHP教程
-
用ADODB来让PHP操作ACCESS数据库的方法_PHP教程
-
命令行向php传入参数的两种方法_PHP教程
-
[PHP]CodeIgniter学习手册(一):控制器Controller的介绍与使用
-
win7下memCache的安装过程(具体操作步骤)_PHP教程
-
基于PHP导出Excel的小经验 完美解决乱码问题_PHP教程
-
我想问一下PHP的学习路线图?