我怎么用树枝做这个?
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 %}