gpt4 book ai didi

symfony - 检查 Twig 数组中是否存在值

转载 作者:行者123 更新时间:2023-12-02 10:24:48 25 4
gpt4 key购买 nike

我的 Twig 中有一个这样的数组

array:19 [
0 => array:2 [
"Title" => "view_subscription_plan"
"Description" => "View subscription plan"
]
1 => array:2 [
"Title" => "view_subscription_period"
"Description" => "View subscription period"
]
2 => array:2 [
"Title" => "view_subscription_details"
"Description" => "View subscription details"
]
3 => array:2 [
"Title" => "create_department"
"Description" => "Create Department"
]
4 => array:2 [
"Title" => "edit_department"
"Description" => "Edit Department"
]
5 => array:2 [
"Title" => "view_department"
"Description" => "View Department"
]
6 => array:2 [
"Title" => "delete_department"
"Description" => "Delete Department"
]
7 => array:2 [
"Title" => "create_division"
"Description" => "Create Division"
]
8 => array:2 [
"Title" => "edit_division"
"Description" => "Edit Division"
]
9 => array:2 [
"Title" => "view_division"
"Description" => "View Division"
]
10 => array:2 [
"Title" => "delete_division"
"Description" => "Delete Division"
]
11 => array:2 [
"Title" => "create_basic_info"
"Description" => "Create employee basic info"
]
12 => array:2 [
"Title" => "edit_basic_info"
"Description" => "Edit employee basic info"
]
13 => array:2 [
"Title" => "view_basic_info"
"Description" => "View employee basic info"
]
14 => array:2 [
"Title" => "delete_basic_info"
"Description" => "Delete employee basic info"
]
15 => array:2 [
"Title" => "create_salary"
"Description" => "Create Salary"
]
16 => array:2 [
"Title" => "edit_salary"
"Description" => "Edit Salary"
]
17 => array:2 [
"Title" => "view_salary"
"Description" => "View Salary"
]
18 => array:2 [
"Title" => "delete_salary"
"Description" => "Delete Salary"
]
]

我想检查该数组中是否存在某个值。与 PHP 中的 in_array 非常相似。 我不想检查 key 是否存在该数组是动态的。上面给出的数组是 symfony 的转储版本。

最佳答案

如果你想检查值是否存在(与 PHP 中的 in_array() 相同):

{% if value in array %}

检查 key 是否存在:

{% if key in array|keys %}

关于symfony - 检查 Twig 数组中是否存在值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34870091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com