私はこのような「ギャップ」を持つ配列を持っています:
$arr = array (
"bananas" => array (
"2010-01-01" => "10.1",
"2010-01-02" => "11.4",
"2010-01-05" => "13.3", //missing 03, 04
"2010-01-06" => "09.2",
"2010-01-07" => "11.1" ),
"grapes" => array (
"2011-01-05" => "20.1",
"2011-01-06" => "21.4",
"2011-01-07" => "23.3",
"2011-01-08" => "29.2",
"2011-01-10" => "21.1", //missing 09
"2011-01-11" => "21.0" ),
"coconuts" => array (
"2012-01-28" => "50.1",
"2012-01-29" => "51.4",
"2012-02-02" => "53.3", //missing 30, 31, 01
"2012-02-03" => "51.1" )
);
配列にいくつの商品と「date=>price」があるのかわかりません。
不足している日付をギャップ前の最終価格で埋めるにはどうすればよいですか?
重要:日付は異なる月になる可能性があります(を参照してください"coconuts"
)。
結果は次のようになります。
$arr = array (
"bananas" => array (
"2010-01-01" => "10.1",
"2010-01-02" => "11.4", //was last price before gap
"2010-01-03" => "11.4", //filling missing
"2010-01-04" => "11.4", //filling missing
"2010-01-05" => "13.3",
"2010-01-06" => "09.2",
"2010-01-07" => "11.1" ),
"grapes" => array (
"2011-01-05" => "20.1",
"2011-01-06" => "21.4",
"2011-01-07" => "23.3",
"2011-01-08" => "29.2", //was last price before gap
"2011-01-09" => "29.2", //filling missing
"2011-01-10" => "21.1",
"2011-01-11" => "21.0" ),
"coconuts" => array (
"2012-01-28" => "50.1",
"2012-01-29" => "51.4", //was last price before gap
"2012-01-30" => "51.4", //filling missing
"2012-01-31" => "51.4", //filling missing
"2012-02-01" => "51.4", //filling missing
"2012-02-02" => "53.3",
"2012-02-03" => "51.1" )
);
お時間をいただきありがとうございます。