Symfony2 中 Yaml 中的参数作为数组 [英] Parameters as array in Yaml in Symfony2
本文介绍了Symfony2 中 Yaml 中的参数作为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在这样做,效果很好:
I'm doing this which works fine:
parameters:
array_name1: [a, b, c, d]
array_name2: [x, y, a, b]
现在我需要在 PHP 中添加 $array_name3[1] = array("a", "b", "c") 等,所以是这样的:
Now I need to add what in PHP would be $array_name3[1] = array("a", "b", "c") etc., so something like this:
parameters:
array_name3[1]: [1, 2, 3]
array_name3[2]: [a, b, c]
array_name3[3]: [x, y, z]
...这当然行不通.我尝试的任何东西似乎都没有被接受.
...which of course doesn't work. Nothing I try seems to be accepted.
如何在 Yaml (Symfony2) 中定义多维数组?
How do I define multi-dimensional arrays in Yaml (Symfony2)?
推荐答案
试试这个
parameters:
array_name3:
- [1, 2, 3]
- [a, b, c]
- [x, y, z]
或者,如果您想让它具有关联性:
Or if you want to have it associative:
parameters:
array_name3:
1: [1, 2, 3]
2: [a, b, c]
bla: [x, y, z]
或者如果你想要更多 - 阅读文档
Or if you want more - read documentation
这篇关于Symfony2 中 Yaml 中的参数作为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文