小枝でこれを行うにはどうすればよいですか?
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 %}