如何用樹枝做到這一點?用樹枝環行
foreach($estimate_data AS $year => $month) {
foreach ($month AS $monthNo => $estimates) {
$chart_data .= "['". $year ."/".$monthNo."',";
foreach (array(0, 1, 3, 5, 8, 13, 20) AS $est){
$chart_data .= (isset($estimates[$est]) ? $estimates[$est] : 0) .",";
}
$chart_data .= "],\n";
}
}
這是我到目前爲止,但我與內的foreach掙扎和檢查元素的存在數組中:
{% for year, month in chart_data %}
{% for month_no, estimates in month %}
['{{year}}/{{month_no}}',
{% for i in [0, 1, 2, 3, 5, 8, 13, 20] %}
{% if estimates %}
{{estimates[i]}} ,
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
你得到了什麼不工作或者是什麼錯誤? – mpm 2013-04-29 20:05:07
@mpm密鑰「2」用於鍵值爲「0,1,3,5,8」的數組在ApplicationDefaultBundle中不存在:Estimates:index.html.twig在第17行 – Mike 2013-04-30 06:18:34