$list
is populated thusly: -
$list[$i++] = array(
"date" => $date,
"desc" => $desc,
"priority" => $priority
);
$priority
is set to TRUE
if it matches some criteria.
I'd like the $list
to be sorted with rows that have a priority TRUE
at the top.
The list is already sorted by date which I wish to preserve.
In PHP>=5.3
usort ($array, function ($left, $right) {
return $left['priority'] - $right['priority'];
});
Or in earlier version
function cmp($left, $right) {
return $left['priority'] - $right['priority'];
}
usort($array, 'cmp');
Or use create_function() (also for version < 5.3)
usort ($array, create_function('$left,$right', 'return $left[\'priority\'] - $right[\'priority\'];'));
This works, because (int) true === 1
and (int) false === 0
true - true == 0
true - false == 1
false - true == -1
false - false == 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With