Php 细枝:如何在数组中写入if

Php 细枝:如何在数组中写入if,php,arrays,if-statement,twig,Php,Arrays,If Statement,Twig,我有以下php语句: <?php if(in_array(get_theme_mod('navbar_position'), array('under-header', 'bottom-of-header'))) { ?> 会不会是这样的: {% if theme.theme_mod('navbar_position') in 'under-header', 'bottom-of-header'|keys %} …有点暗中刺伤。PHP: if (in_array(get_them

我有以下php语句:

<?php if(in_array(get_theme_mod('navbar_position'), array('under-header', 'bottom-of-header'))) { ?>
会不会是这样的:

{% if theme.theme_mod('navbar_position') in 'under-header', 'bottom-of-header'|keys %}
…有点暗中刺伤。

PHP:

if (in_array(get_theme_mod('navbar_position'), array('under-header', 'bottom-of-header'))) {
{% if theme.theme_mod('navbar_position') in ['under-header', 'bottom-of-header'] %}
您不需要应用
| keys
过滤器,因为您不是在测试密钥。 函数的第二个参数是直接在其中声明的数组,使用Twig必须使用
[]
声明它

小枝:

if (in_array(get_theme_mod('navbar_position'), array('under-header', 'bottom-of-header'))) {
{% if theme.theme_mod('navbar_position') in ['under-header', 'bottom-of-header'] %}

你在用木料吗?不在数组中如何?@RazvanZamfir使用“不在”