我的树枝上有一个这样的数组
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非常相似的东西。 我不想检查密钥是否存在。 此阵列是动态的。上面给出的数组是symfony的转储版本。
答案 0 :(得分:25)
如果要检查值是否存在(与PHP中的in_array()
相同):
{% if value in array %}
检查密钥是否存在:
{% if key in array|keys %}