Ho la seguente matrice:Ordina serie da due proprietà degli oggetti utilizzando funzione anonima
Array
(
[0] => stdClass Object
(
[timestamp] => 1
[id] => 10
)
[1] => stdClass Object
(
[timestamp] => 123
[id] => 1
)
[2] => stdClass Object
(
[timestamp] => 123
[id] => 2
)
)
Attualmente sto usando il seguente codice per ordinare l'array dalla proprietà timestamp:
function sort_comments_by_timestamp(&$comments, $prop)
{
usort($comments, function($a, $b) use ($prop) {
return $a->$prop < $b->$prop ? 1 : -1;
});
}
Come posso anche ordinare l'ID per id
discendente quando il timestamp è lo stesso?
C'è un motivo per cui lo chiamate '_by_timestamp', ma ha anche un parametro' $ prop'? – Matthew
@Matthew diverso da "Stavo facendo alcuni test' e cattivi nomi? No :) Già risolto btw – PeeHaa