TWIG的 tests 学习_PHP教程

WBOY
풀어 주다: 2016-07-13 17:48:10
원래의
999명이 탐색했습니다.

做逻辑判断的。目前支持的有

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的专栏

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478456.htmlTechArticle做逻辑判断的。目前支持的有 divisibleby null even odd sameas constant defined empty divisibleby 检查是否能被整除 {% if loop.index is divisibleby(3) %} ... {% en...
로그인 후 복사
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!