我在 Twig 中渲染嵌套数组时遇到问题。这是我的 PHP 逻辑,我可以在其中获取其他字段,例如名称 URL,但不能获取数组数据。请检查树枝代码,我想我在那里做错了什么。错误:在渲染模板期间抛出异常(“注意:数组到字符串的转换”)。
foreach ($arrays as $array) {
foreach ($array as $key => $value) {
$allProjects[$key][] = $value;
}
}
{% for project in projects %}
<tr>
<td>{{ project.name }}</td>
<td>{{ project.url }}</td>
<td>{{ project.assingedApprover }}</td>
<td></td>
</tr>
{% endfor %}
JSON 数据
[
{
"name": "Resolute Energy Corporation",
"url": "http://msu.edu",
"assignedAprover": [
{
"firstName": "Joe",
"lastName": "lastName"
},
{
"firstName": "men",
"lastName": "gen"
}
]
},
{
"name": "CBL & Associates Properties, Inc.",
"url": "http://acquirethisname.com",
"assignedAprover": [
{
"firstName": "Joe",
"lastName": "lastName"
},
{
"firstName": "men",
"lastName": "gen"
}
]
},
]
子衿沉夜