<?php
$tickets = array(
array(
'id' => 13,
'pid' => 1,
'owner' => 'jachim',
'time' => '2009-09-25 10:39:42.011612',
'project' => 'jachim.be',
'title' => 'Some random ticket'
),
array(
'id' => 31,
'pid' => 2,
'owner' => 'jachim',
'time' => '2009-09-24 14:38:47.945020',
'project' => 'joggink.be',
'title' => 'Some other random ticket'
),
array(
'id' => 22,
'pid' => 3,
'owner' => 'root',
'time' => '2009-09-24 10:58:02.904198',
'project' => 'joggink.be',
'title' => 'A specific ticket'
),
array(
'id' => 18,
'pid' => 3,
'owner' => 'root',
'time' => '2009-09-24 10:58:02.904198',
'project' => 'joggink.be',
'title' => 'A specific ticket'
)
);
function msort($array, $key, $sort_flags = SORT_REGULAR) {
if (is_array($array) && count($array) > 0) {
if (!empty($key)) {
$mapping = array();
foreach ($array as $k => $v) {
$sort_key = '';
if (!is_array($key)) {
$sort_key = $v[$key];
} else {
// @TODO This should be fixed, now it will be sorted as string
foreach ($key as $key_key) {
$sort_key .= $v[$key_key];
}
$sort_flags = SORT_STRING;
}
$mapping[$k] = $sort_key;
}
asort($mapping, $sort_flags);
$sorted = array();
foreach ($mapping as $k => $v) {
$sorted[] = $array[$k];
}
return $sorted;
}
}
return $array;
}
//var_dump($tickets);
$tickets = msort($tickets, array('pid','id'));
var_dump($tickets);
?>
- Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- array(4) {
[0]=>
array(6) {
["id"]=>
int(13)
["pid"]=>
int(1)
["owner"]=>
string(6) "jachim"
["time"]=>
string(26) "2009-09-25 10:39:42.011612"
["project"]=>
string(9) "jachim.be"
["title"]=>
string(18) "Some random ticket"
}
[1]=>
array(6) {
["id"]=>
int(31)
["pid"]=>
int(2)
["owner"]=>
string(6) "jachim"
["time"]=>
string(26) "2009-09-24 14:38:47.945020"
["project"]=>
string(10) "joggink.be"
["title"]=>
string(24) "Some other random ticket"
}
[2]=>
array(6) {
["id"]=>
int(18)
["pid"]=>
int(3)
["owner"]=>
string(4) "root"
["time"]=>
string(26) "2009-09-24 10:58:02.904198"
["project"]=>
string(10) "joggink.be"
["title"]=>
string(17) "A specific ticket"
}
[3]=>
array(6) {
["id"]=>
int(22)
["pid"]=>
int(3)
["owner"]=>
string(4) "root"
["time"]=>
string(26) "2009-09-24 10:58:02.904198"
["project"]=>
string(10) "joggink.be"
["title"]=>
string(17) "A specific ticket"
}
}
preferences:
261.14 ms | 408 KiB | 356 Q