【发布时间】:2019-09-30 11:38:45
【问题描述】:
我得到了这样的 yml 配置:
test_array:
dynamic_key:
- 'this_is_value'
- 'it_is_also_a_value'
second_dynamic_key:
- 'yop, value'
- 'another value'
配置后,我想得到一个这样的数组:
$iNeedToGetArrayLikeThis = [
'dynamic_key' => [
'this_is_value',
'it_is_also_a_value'
],
'second_dynamic_key' => [
'yop, value',
'another value'
]
];
但我明白了:
$whatIGet = [
[
'dynamic_key' => [
'this_is_value',
'it_is_also_a_value'
],
'second_dynamic_key' => [
'yop, value',
'another value'
]
],
];
我尝试使用->useAttributeAsKey(),但也没有用。
我的代码配置代码:
->children()
->arrayNode('test_array')
->ignoreExtraKeys(true)
->arrayPrototype()
->prototype('scalar')
->end()
->end()
->end()
->end()
->end()
【问题讨论】:
-
你能用
$whatIGet[0]吗?
标签: php symfony dependency-injection yaml