我在symfony中有一个后端API,在vueJs中有前端,在我的应用程序中,我有一个获取表单定义的路径...
但是对于entityType,我需要有选择列表,所以我这样做:
$result['choice'] = array_reduce($config->getOption('choice_list')
->getChoices(), function ($carry, $item) {
return array_merge($carry, [(string)$item->getId() => (string)$item]);
}, []);
从理论上讲,这回归了:
[ "0" => "value1", "1" => "value2", "3" => "value3" ... ]
( note, key are not necessary continue)
实际上,调试器说“0”是数字,所以是int!并且JMS或json_encode做同样的事情......在序列化之后,我有一个没有密钥的简单数组!
如何获取JMS或本机PHP函数来获取真正的关联数组?
$result['choice'] = array_reduce($config->getOption('choice_list')
->getChoices(), function ($carry, $item) {
return array_merge($carry, ["0{$item->getId()}" => (string)$item]);
}, []);
concat“0”前面的id做诀窍:)
我的表单中有一个“假的”字符串ID ...但是当我提交表单时... symfony将“01”转换为int ^^