second sorting with php usort
Posted
by bluedaniel
on Stack Overflow
See other posts from Stack Overflow
or by bluedaniel
Published on 2010-05-20T16:03:14Z
Indexed on
2010/05/20
16:10 UTC
Read the original article
Hit count: 233
So Ive got a pretty big array of data and need to sort them by two criteria.
There is variable $data['important']
and $data['basic']
.
They are simple numbers and I am using uasort to sort
$data
firstly by important and then by basic.
So
Important | Basic
10 | 8
9 | 9
9 | 7
7 | 9
The usort function is a simple
public function sort_by_important($a, $b) {
if ($a[important] > $b[important]) {
return -1;
}
elseif ($b[important] > $a[important]) {
return 1;
}
else {
return 0;
}
}
How can I re-sort the array to the second variable and keep the Important ordering?
Thanks everyone.
EDIT
How about adding a third sorting option after this even? So Important > Basic > Less
© Stack Overflow or respective owner