我有一个日历日期数组和一个多维报告数组,其中报告的键是日期
日历日期结构数组
Array
(
[1] => 2014-05-01
[2] => 2014-05-02
[3] => 2014-05-03
[4] => 2014-05-04
[5] => 2014-05-05
[6] => 2014-05-06
[7] => 2014-05-07
[8] => 2014-05-08
[9] => 2014-05-09
[10] => 2014-05-10
[11] => 2014-05-11
[12] => 2014-05-12
[13] => 2014-05-13
[14] => 2014-05-14
[15] => 2014-05-15
[16] => 2014-05-16
[17] => 2014-05-17
[18] => 2014-05-18
[19] => 2014-05-19
[20] => 2014-05-20
[21] => 2014-05-21
[22] => 2014-05-22
[23] => 2014-05-23
[24] => 2014-05-24
[25] => 2014-05-25
[26] => 2014-05-26
[27] => 2014-05-27
[28] => 2014-05-28
[29] => 2014-05-29
[30] => 2014-05-30
[31] => 2014-05-31
)
和我的数组报告结构
Array
(
[2014-05-01] => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
[4] => 21
[5] => 22
[6] => 15
[7] => 14
[8] => 13
[9] => 1
[10] => 3
[11] => 4
[12] => 5
[13] => 12
)
[2014-05-03] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
[4] => 40
)
[2014-05-11] => Array
(
[0] => 2
[1] => 5
[2] => 4
[3] => 3
[4] => 7
[5] => 8
[6] => 9
[7] => 10
[8] => 6
[9] => 1
)
[2014-05-17] => Array
(
[0] => 3
[1] => 10
[2] => 9
[3] => 8
[4] => 7
[5] => 6
[6] => 2
[7] => 5
[8] => 4
[9] => 1
)
[2014-05-18] => Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 1
)
[2014-05-19] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
)
[2014-05-20] => Array
(
[0] => 1
[1] => 9
[2] => 8
[3] => 7
[4] => 6
[5] => 2
[6] => 5
[7] => 4
[8] => 3
[9] => 10
)
[2014-05-26] => Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 5
)
[2014-05-27] => Array
(
[0] => 10
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 9
[6] => 1
[7] => 6
[8] => 8
[9] => 7
)
)
现在我想循环通过日历和日历数组中的每个值(日期)匹配报告数组的键(例如日期),我想将报告附加到日历值并使用值日历作为报告的键,否则我想添加一个字符串说没有完成报告。
我认为我应该这样做
foreach ($calendar as $cal)
{
foreach ($report as $key => $rdate)
{
if ($key == $cal)
{
$calendar[][$cal] = $rdate;
}
}
}
然而,只是将它们添加到日历数组的末尾,而不是日历值和报告键匹配的地方。
Like so
Array
(
[1] => 2014-05-01
[2] => 2014-05-02
[3] => 2014-05-03
[4] => 2014-05-04
[5] => 2014-05-05
[6] => 2014-05-06
[7] => 2014-05-07
[8] => 2014-05-08
[9] => 2014-05-09
[10] => 2014-05-10
[11] => 2014-05-11
[12] => 2014-05-12
[13] => 2014-05-13
[14] => 2014-05-14
[15] => 2014-05-15
[16] => 2014-05-16
[17] => 2014-05-17
[18] => 2014-05-18
[19] => 2014-05-19
[20] => 2014-05-20
[21] => 2014-05-21
[22] => 2014-05-22
[23] => 2014-05-23
[24] => 2014-05-24
[25] => 2014-05-25
[26] => 2014-05-26
[27] => 2014-05-27
[28] => 2014-05-28
[29] => 2014-05-29
[30] => 2014-05-30
[31] => 2014-05-31
[32] => Array
(
[2014-05-01] => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
[4] => 21
[5] => 22
[6] => 15
[7] => 14
[8] => 13
[9] => 1
[10] => 3
[11] => 4
[12] => 5
[13] => 12
)
)
[33] => Array
(
[2014-05-03] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
[4] => 40
)
)
[34] => Array
(
[2014-05-11] => Array
(
[0] => 2
[1] => 5
[2] => 4
[3] => 3
[4] => 7
[5] => 8
[6] => 9
[7] => 10
[8] => 6
[9] => 1
)
)
[35] => Array
(
[2014-05-17] => Array
(
[0] => 3
[1] => 10
[2] => 9
[3] => 8
[4] => 7
[5] => 6
[6] => 2
[7] => 5
[8] => 4
[9] => 1
)
)
[36] => Array
(
[2014-05-18] => Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 1
)
)
[37] => Array
(
[2014-05-19] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
)
)
[38] => Array
(
[2014-05-20] => Array
(
[0] => 1
[1] => 9
[2] => 8
[3] => 7
[4] => 6
[5] => 2
[6] => 5
[7] => 4
[8] => 3
[9] => 10
)
)
[39] => Array
(
[2014-05-26] => Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 5
)
)
[40] => Array
(
[2014-05-27] => Array
(
[0] => 10
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 9
[6] => 1
[7] => 6
[8] => 8
[9] => 7
)
)
)
我想要这个
Array (
[1] => 2014-05-01 => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
...........
)
我想我一直在用头撞墙的地方,我不能从树上看到树林。
任何帮助都是伟大的,任何指导都是伟大的。
问候迈克
通过写出来,我一定算出来了这实际上帮助了我形成了这个问题,这就是我改变的
foreach ($dates_month_with_reports as $cal)
{
foreach ($reportdates as $key => $rdate)
{
if ($key == $cal)
{
//took away the extra array
$dates_month_with_reports[$cal] = $rdate;
}
}
}
在日历数组中,我也将日期添加到键中现在我得到了这个
Array
(
[2014-05-01] => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
[4] => 21
[5] => 22
[6] => 15
[7] => 14
[8] => 13
[9] => 1
[10] => 3
[11] => 4
[12] => 5
[13] => 12
)
[2014-05-02] => 2014-05-02
[2014-05-03] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
[4] => 40
)
[2014-05-04] => 2014-05-04
[2014-05-05] => 2014-05-05
[2014-05-06] => 2014-05-06
[2014-05-07] => 2014-05-07
[2014-05-08] => 2014-05-08
[2014-05-09] => 2014-05-09
[2014-05-10] => 2014-05-10
[2014-05-11] => Array
(
[0] => 2
[1] => 5
[2] => 4
[3] => 3
[4] => 7
[5] => 8
[6] => 9
[7] => 10
[8] => 6
[9] => 1
)
[2014-05-12] => 2014-05-12
[2014-05-13] => 2014-05-13
[2014-05-14] => 2014-05-14
[2014-05-15] => 2014-05-15
[2014-05-16] => 2014-05-16
[2014-05-17] => Array
(
[0] => 3
[1] => 10
[2] => 9
[3] => 8
[4] => 7
[5] => 6
[6] => 2
[7] => 5
[8] => 4
[9] => 1
)
[2014-05-18] => Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 1
)
[2014-05-19] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
)
[2014-05-20] => Array
(
[0] => 1
[1] => 9
[2] => 8
[3] => 7
[4] => 6
[5] => 2
[6] => 5
[7] => 4
[8] => 3
[9] => 10
)
[2014-05-21] => 2014-05-21
[2014-05-22] => 2014-05-22
[2014-05-23] => 2014-05-23
[2014-05-24] => 2014-05-24
[2014-05-25] => 2014-05-25
[2014-05-26] => Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 5
)
[2014-05-27] => Array
(
[0] => 10
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 9
[6] => 1
[7] => 6
[8] => 8
[9] => 7
)
[2014-05-28] => 2014-05-28
[2014-05-29] => 2014-05-29
[2014-05-30] => 2014-05-30
[2014-05-31] => 2014-05-31
)
我很抱歉浪费你的时间,我不是故意的,但我写完问题后,我明白了。
$calendar1 = array();
foreach ($calendar as $cal)
{
foreach ($report as $key => $rdate)
{
if ($key == $cal)
{
$calendar1[][$cal] = $rdate;
}
}
}