私は2つの配列を持っています。ここで、1 つの配列要素を新しい配列に設定する必要があることに基づいて、両方の配列のいくつかの要素を比較したいと考えています。
Array1: $days this is an array of elements between two dates.
$days = Array
(
[0] => 2012-06-23
[1] => 2012-06-24
[2] => 2012-06-25
[3] => 2012-06-26
[4] => 2012-06-27
[5] => 2012-06-28
[6] => 2012-06-29
[7] => 2012-06-30
[8] => 2012-07-01
[9] => 2012-07-02
[10] => 2012-07-03
[11] => 2012-07-04
[12] => 2012-07-05
[13] => 2012-07-06
[14] => 2012-07-07
[15] => 2012-07-08
[16] => 2012-07-09
[17] => 2012-07-10
[18] => 2012-07-11
[19] => 2012-07-12
[20] => 2012-07-13
[21] => 2012-07-14
[22] => 2012-07-15
[23] => 2012-07-16
)
Array2: $summary is the array which i am getting from the database..
$summary = Array
(
[0] => Array
(
[date] => 2012-06-23
[no_of_posts] => 1
)
[1] => Array
(
[date] => 2012-06-24
[no_of_posts] => 2
)
[2] => Array
(
[date] => 2012-06-25
[no_of_posts] => 1
)
[3] => Array
(
[date] => 2012-06-26
[no_of_posts] => 1
)
[4] => Array
(
[date] => 2012-06-27
[no_of_posts] => 1
)
これらの両方の配列から、ある日付に対して投稿がない場合、この日付に何度も投稿があることを示す配列が必要です。その場合はゼロになるはずです。私はこのようにしてみました.....
$result = array();
foreach($summary as $key=>$s) {
foreach($days as $d) {
if($s['date'] == $d) {
$result[$d] = $s['no_of_posts'];
} else {
$result[$d] = 0;
}
}
}
私は見つけることができない間違いがあることを知っています...........どんなアイデアでも。
出力配列は以下のようにする必要があります.....
$result = Array
Array
(
[2012-06-23] = 1
[2012-06-24] = 2
[2012-06-25] = 1
[2012-06-26] = 1
[2012-06-27] = 1
[2012-06-28] = 0
[2012-06-29] = 0
[2012-06-30] = 0
[2012-07-01] = 0
[2012-07-02] = 0
[2012-07-03] = 0
[2012-07-04] = 0
[2012-07-05] = 0
[2012-07-06] = 0
[2012-07-07] = 0
[2012-07-08] = 0
[2012-07-09] = 0
[2012-07-10] = 0
[2012-07-11] = 0
[2012-07-12] = 0
[2012-07-13] = 0
[2012-07-14] = 0
[2012-07-15] = 0
[2012-07-16] = 0
)