我有一个这样的事件数组:
Array (
[0] = Array(
[EventId] => 596
[Event] => test
[ResourceId] => 6
[StartDate] => 2013-06-21 10:00:00
[FinishDate] 2013-06-21 10:30:00
)
[1] = Array(
[EventId] => 598
[Event] => another test
[ResourceId] => 6
[StartDate] => 2013-06-21 15:00:00
[FinishDate] 2013-06-21 16:30:00
)
[2] = Array(
[EventId] => 599
[Event] => test
[ResourceId] => 8
[StartDate] => 2013-06-21 10:00:00
[FinishDate] 2013-06-21 10:30:00
)
[3] = Array(
[EventId] => 601
[Event] => another test
[ResourceId] => 10
[StartDate] => 2013-06-21 15:00:00
[FinishDate] 2013-06-21 16:30:00
)
[4] = Array(
[EventId] => 602
[Event] => new event
[ResourceId] => 10
[StartDate] => 2013-06-22 10:00:00
[FinishDate] 2013-06-22 12:30:00
)
[5] = Array(
[EventId] => 604
[Event] => try new event
[ResourceId] => 6
[StartDate] => 2013-06-22 10:00:00
[FinishDate] 2013-06-22 12:30:00
)
)
我想要来自事件数组的结果数组,如下所示:
Array (
[0] = Array(
[EventId] => 596,599
[Event] => test
[ResourceId] => 6,8
[StartDate] => 2013-06-21 10:00:00
[FinishDate] 2013-06-21 10:30:00
)
[1] = Array(
[EventId] => 598,601
[Event] => another test
[ResourceId] => 6,10
[StartDate] => 2013-06-21 15:00:00
[FinishDate] 2013-06-21 16:30:00
)
[2] = Array(
[EventId] => 602
[Event] => new event
[ResourceId] => 10
[StartDate] => 2013-06-22 10:00:00
[FinishDate] 2013-06-22 12:30:00
)
[3] = Array(
[EventId] => 604
[Event] => try new event
[ResourceId] => 6
[StartDate] => 2013-06-22 10:00:00
[FinishDate] 2013-06-22 12:30:00
)
)
我正在研究 PHP。但我不知道如何迭代数组以匹配它的 2 个值并添加到新数组中。
我需要匹配 StartDate 和 EndDate。如果两者相同,则我需要连接资源 ID 并合并该记录。
我尝试了 for 循环,但它没有用。
我试过这个:
for($i=0;$i<count($event);$i++)
{
if(($event[$i]["StartDate"]==$event[$i+1]["StartDate"]) && ($event[$i]["FinishDate"]==$event[$i+1]["FinishDate"]))
{
echo "yes"."<br>"; // Add in new array
}
else
{
echo "no"."<br>";
}
}
谁能帮帮我吗 ?
提前致谢。