我有此代码,该代码应该用于对从对象检索的for循环中的项目进行计数。此代码在使用PHP 7.2.5和Twig 5.0的symfony 5.0项目上运行]
{% set sent_mails = 0 %}
{% for email in emails if email.status == 1 %}
{% set sent_mails = (sent_mails + 1) %}
{% endfor %}
{{ sent_mails }}
并且出现以下错误:
[当我使用PHP 7.1.3和twig-bundle 4.2在Symfony 4.2上运行相同的代码时,一切正常,没有错误。
我没有正确使用的树枝束代码语法有什么变化,或者我缺少什么?
尝试一下:
{% set sent_mails = 0 %}
{% for email in emails %}
{% if email.status == 1 %}
{% set sent_mails = (sent_mails + 1) %}
{% endif %}
{% endfor %}
{{ sent_mails }}