gpt4 book ai didi

for-loop - symfony2 和 twig 用于子阵列

转载 作者:行者123 更新时间:2023-12-01 01:18:59 25 4
gpt4 key购买 nike

好的,我有一个看起来像的数组。

[0] => Array (
first_name => j,
last_name => b,
times => Array(
[0] => Array(
[in1] => a date here
[out1] => a date here
[in2] => a date here
[out2] => a date here
)
[1] => Array(
[in1] => another date here
[out1] => another date here
[in2] => another date here
[out2] => another date here
)))

为了 SO 布局,我简化了阵列的外观......

这个列表的开始数组中经常会有超过 100 个不同的人,这些人都需要输出到浏览器......这很好,我可以做到......
{% for entity in entity %}
<h3>{{ entity.first_name }} {{ entity.last_name }} ( {{ start|date("m/d/Y") }} - {{ end|date("m/d/Y")}} )</h3>

<table = border="1" cellpadding="5" cellspacing="0">
<thead>
<tr>
<th>Date</th>
<th>In</th>
<th>Lunch Out</th>
<th>Lunch In</th>
<th>Out</th>
<th>Extra In</th>
<th>Extra Out</th>
<th>Total Time</th>
</tr>
</thead>
<tbody>
{% for times in entity.times %}
<tr>
<td>{{ entity.times.daydate|date("M jS Y") }} </td>
<td>{{ entity.times.in1 is empty ? "" : entity.times.in1|date("h:i A") }}</td>
<td>{{ entity.times.out1 is empty ? "" : entity.times.out1|date("h:i A") }}</td>
<td>{{ entity.times.in2 is empty ? "" : entity.times.in2|date("h:i A") }}</td>
<td>{{ entity.times.out2 is empty ? "" : entity.times.out2|date("h:i A") }}</td>
<td>{{ entity.times.in3 is empty ? "" : entity.times.in3|date("h:i A") }}</td>
<td>{{ entity.times.out3 is empty ? "" : entity.times.out3|date("h:i A") }}</td>
<td>{{ entity.times.totaltime }} Hours</td>
</tr>
{% endfor%}
</tbody>
</table>
{% endfor %}

那是我当前的 Twig 代码......我需要帮助的是因为每个“实体”都有一个 .times 子数组,也需要循环遍历......这样做的正确方法是什么?

最佳答案

{% for entity in entities %}
<h3>{{ entity.foo }}</h3>

{% for time in entity.times %}
<p>{{ time.bar }}</p>
{% endfor %}
{% endfor %}

我已经简化了代码,以便更容易看到您正在寻找的概念。

关于for-loop - symfony2 和 twig 用于子阵列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10359220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com