【发布时间】:2017-02-05 22:19:25
【问题描述】:
我不是英语母语,并且是 stackoverflow 上的新手,所以如果我做错了事,请纠正我。 我的问题是我从两个不同的mysql数据库名称表中检索数据。
- 事件
- 留言
用于获取数据的代码如下。
$msgres=$ticket->getMessages();
$arr1 = array();
while($msg_row_one = db_fetch_array($msgres)){
$arr1[] = $msg_row_one;
}
$noteres=$ticket->getNotes();
$arr2 = array();
while ($msg_row_two = db_fetch_array($noteres)){
$arr2[] = $msg_row_two;
}
在这个过程之后,我正在合并两个数组。
$arr1[]
$arr2[]
像这样。
$merge = array_merge($arr1,$arr2);
然后我得到一个如下的数组。
Array
(
[0] => Array
(
[msg_id] => 7563
[ticket_id] => 1768
[messageId] =>
[msg_type] => R
[message] => this is a link system . this is a link system .
[staff_id] => 1
[staff_name] => System Administrator
[headers] =>
[source] => staff
[ip_address] => 10.12.145.174
[created] => 2016-09-27 01:49:27
[attachments] => 0
)
[1] => Array
(
[msg_id] => 7562
[ticket_id] => 1768
[messageId] =>
[msg_type] => R
[message] => Last message is this.
[staff_id] => 1
[staff_name] => System Administrator
[headers] =>
[source] => staff
[ip_address] => 10.12.145.174
[created] => 2016-09-26 08:39:46
[attachments] => 0
)
[2] => Array
(
[msg_id] => 7561
[ticket_id] => 1768
[messageId] =>
[msg_type] => R
[message] => Last message is this.
[staff_id] => 1
[staff_name] => System Administrator
[headers] =>
[source] => staff
[ip_address] => 10.12.145.174
[created] => 2016-09-26 08:37:25
[attachments] => 0
)
[3] => Array
(
[msg_id] => 7558
[ticket_id] => 1768
[messageId] =>
[msg_type] => R
[message] => mmmmmmmmmmmmmmmmmmmmmmmmmmm
[staff_id] => 1
[staff_name] => System Administrator
[headers] =>
[source] => staff
[ip_address] => 10.12.145.174
[created] => 2016-09-26 07:47:51
[attachments] => 0
)
)
然后我按以下代码对$merge数组的日期进行降序排序。
$strdate = array();
$formated = array();
foreach ($merge as $ascdate){
$strdate[] = strtotime($ascdate['created']);
}
rsort($strdate);
foreach($strdate as $descdate){
$formated[] = date('Y-m-d H:i:s',$descdate);
}
现在我想代表日期按降序对整个 $merge 数组进行排序。意味着最大的日期$merge 数组应该排在最前面。我不知道如何在$merge 数组中应用上述排序日期$formated。
【问题讨论】:
-
你能展示一些你得到的最终数组吗?或者您可以查看这个有用的答案:- stackoverflow.com/a/2910637/4248328
-
试试这个可能对你有帮助stackoverflow.com/questions/15557373/…
-
接受您之前问题的答案怎么样?