做逻辑判断的。目前支持的有
divisibleby null even odd sameas constant defined empty
立即学习“PHP免费学习笔记(深入)”;
立即学习“PHP免费学习笔记(深入)”;
divisibleby
检查是否能被整除
{% if loop.index is divisibleby(3) %}
...
{% endif %}
{% if loop.index is divisibleby(3) %}
...
{% endif %}
立即学习“PHP免费学习笔记(深入)”;
null
{{ var is null }}
{{ var is null }}
立即学习“PHP免费学习笔记(深入)”;
even
变量是否是偶数{{ var is even }}
{{ var is even }}
odd
变量是否是奇数
{{ var is odd }} <br><pre name="code" class="html">{{ var is odd }}
<p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<p>sameas<br>
检查变量的地址是否相同</p>
<p>{% if foo.attribute is sameas(false) %} <br>
the foo attribute really is the ``false`` PHP value <br>
{% endif %} <br>
{% if foo.attribute is sameas(false) %}<br>
the foo attribute really is the ``false`` PHP value<br>
{% endif %}</p>
<p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<p>constant<br>
检查变量的值是否相同</p>
<p>{% if post.status is constant('Post::PUBLISHED') %} <br>
the status attribute is exactly the same as Post::PUBLISHED <br>
{% endif %} <br>
{% if post.status is constant('Post::PUBLISHED') %}<br>
the status attribute is exactly the same as Post::PUBLISHED<br>
{% endif %}</p>
<p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<p>defined<br>
测试变量是否定义</p>
<p>{# defined works with variable names #} <br>
{% if foo is defined %} <br>
... <br>
{% endif %} <br>
<br>
{# and attributes on variables names #} <br>
{% if foo.bar is defined %} <br>
... <br>
{% endif %} <br>
<br>
{% if foo['bar'] is defined %} <br>
... <br>
{% endif %} <br>
{# defined works with variable names #}<br>
{% if foo is defined %}<br>
...<br>
{% endif %}</p>
<p>{# and attributes on variables names #}<br>
{% if foo.bar is defined %}<br>
...<br>
{% endif %}</p>
<p>{% if foo['bar'] is defined %}<br>
...<br>
{% endif %}</p>
<p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<p>empty<br>
测试变量是否为空,empty的意思是:该变量已经定义,但他的值是 null false 或者是空字符串<br>
{# evaluates to true if the foo variable is null, false, or the empty string #} <br>
{% if foo is empty %} <br>
... <br>
{% endif %} <br><br>
摘自 jiaochangyun的专栏</p>
<p align="left"></p><div style="display:none;">
<span id="url" itemprop="url">http://www.bkjia.com/PHPjc/478456.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/478456.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">做逻辑判断的。目前支持的有 divisibleby null even odd sameas constant defined empty divisibleby 检查是否能被整除 {% if loop.index is divisibleby(3) %} ... {% en...</span>
</div>
<div class="art_confoot"></div>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号