I have a nested JSON array within PHP which contains the following fields:
{
"items": [{
"id": "8498",
"title": "Item 2",
"pubdate": "2015-03-01 10:29:00 +0000",
}, {
"id": "8497",
"title": "Item 1",
"pubdate": "2015-03-01 16:29:00 +0000",
}
}]
}
and I would like to re-order the nodes in the Items array so that they are ordered first by pubdate (oldest to newest), and then within pubdate, for each time, by ID (smallest to largest), if that makes sense?
Currently i'm using the below function, but it only accepts 1 sort value (which im currently using to pubdate). Could I modify it to accept two, in the manner above?
function subval_sort($a,$subkey) {
foreach($a as $k=>$v) {
$b[$k] = strtolower($v[$subkey]);
}
asort($b);
foreach($b as $key=>$val) {
$c[] = $a[$key];
}
return $c;
}
$json_o['items'] = subval_sort($json_o['items'],'pubdate');