我有两个数组:
ARRAY1:
Array ( [id] => 1 [time] => 12:10:23 [date] => 2013-03-24 )
数组2:
Array ( [id] => 2 [time] => 12:10:25 [date] => 2013-03-25 )
我想将它们合并,因此它们会导致以下内容(已编辑):
Array ( [id] => 1
=> 2
[time] => 12:10:23
=> 12:10:25
[date] => 2013-03-24
=> 2013-03-25
)
这可能吗?
答案 0 :(得分:2)
如果你真的想要输出:
Array (
Array ([id] => 1 [time] => 12:10:23 [date] => 2013-03-24 ),
Array ([id] => 2 [time] => 12:10:25 [date] => 2013-03-25 )
)
然后您想使用以下代码:
$newArray = array($array1, $array2);
获取具有最新日期的元素:
$most_recent = $newArray[0];
foreach($newArray as $compare)
{
if($compare['time'] > $most_recent['time'])
{
$most_recent = $compare;
}
}