I am not native english, and new on stackoverflow so please correct me if i do something worng. My problem is that i retrieve data from two different tables of mysql database names are.
- Event
- Message
code used for fetching data is below.
$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;
}
After this process i am merging the both array.
$arr1[]
$arr2[]
like this.
$merge = array_merge($arr1,$arr2);
Then i get an array as below.
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
)
)
Then i sorting the dates of $merge
array in descending order by follwing code.
$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);
}
Now i want to sort the whole $merge
array in descending order on behalf of dates. Means the biggest date $merge
array should come on top. I have no idea how to apply above sorted dates $formated
in $merge
array.