小枝忘记阵列密钥 [英] Twig forgets array-keys
问题描述
我在Symfony2的树枝一个奇怪的问题。我使用下面的数组:
I have a weird problem with twig in Symfony2. I am using the following array:
[days] => Array
(
[1] => Array
(
[money] => 9
)
[2] => Array
(
[money] => 21
)
[3] => Array
(
[money] => 38
)
[4] => Array
(
[money] => 6
)
[18] => Array
(
[money] => 6
)
[19] => Array
(
[money] => 3
)
[31] => Array
(
[money] => 11
)
)
要测试这个我用下面的code
to test this I used the following code
{% for key in days %}
{{ key }}<br>
{% endfor %}
但输出显示以下
0
1
2
3
4
5
6
但它应该是这样的。
but it should look like this
1
2
3
4
18
19
31
看起来像树枝将创建新的索引一个新的数组。有没有办法摆脱阵列右手食指?
Looks like twig creates a new array with new indexes. Is there a way to get the right index from array?
使用的var_dump($天)
在PHP中,我可以看到正确的索引,这样的问题,以小枝有关。
With var_dump($days)
in php I can see the right index, so the "problem" is related to twig.
推荐答案
它不是树枝的关系,它的使用embeddedDocuments教义,MongoDB中一个已知的差距。教义不能从embeddedDocuments处理键值,将重新排序,从0开始键,并因此忽略右边键值。谢谢你的好意的帮助:)
It's not related on twig, it's a known gap in doctrine-mongodb using embeddedDocuments. Doctrine can't handle key-Values from embeddedDocuments, it will reorder the keys beginning from 0 and will so ignore the right key-values. Thank you anyway for your help :).
这篇关于小枝忘记阵列密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!