如何检查是否向数组提供了任何值。在PHP中,我在数组中添加如下:
$myArray['index1'] = $someVal1;
$myArray['index2'] = $someVal2;
问题是,当我在Twig中使用|length过滤器时,当$someVal1或$someVal2没有值时,它会给出结果(这些值取自表单,因此不必填写)。所以我想检查整个数组中是否没有提供值,所以:
{% if myArray|what_filter_here? == 0|empty|whatever %} This text should not appear {% endif %}
能在一个条件下完成吗?
类似于:
{% if myArray|length > 0 %}
This text should not appear
{% endif %}
试用empty
-
{% if myArray is empty %} ... {% endif %}