php - 带有键的数组的 Twig for 循环

标签 php arrays loops twig

我使用 Twig,我有一个带有这样键的数组:

array[1] = "alpha"
array[2] = "bravo"
array[3] = "charlie"
array[8] = "delta"
array[9] = "echo"

我想获取 key (1,2,3,8,9) 和内容 (alpha, bravo, charlie, delta, echo)在循环中获取该数组的所有值。

我该如何解决这个问题?

最佳答案

我找到了答案:

{% for key,value in array_path %}
    Key : {{ key }}
    Value : {{ value }}
{% endfor %}

关于php - 带有键的数组的 Twig for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10299202/

相关文章:

php - 当我添加 "next"函数时,jquery 分页中断

php - 在android中从服务器接收图像

PHP/MySQL 从 JSON 数组更新表行

c - 将二维数组传递给 C 中的函数

c - 如何转换此 "for"循环以在 C 中使用 EOF?

php - 在 sql 和 php 中更新多行

php - COM 无法在 IIS PHP 版本 7.2.9 中工作

java - 查找数组中元素的最小值、最大值和平均值

java - 列出素数

c - 欧拉在 C 中的 totient 函数