php - Array - Order by value then priority if matching values -
php - Array - Order by value then priority if matching values -
the aim code find 3 lowest values, however, if 2 of them matching needs prioritise 1 appears in bottom 3.
this array:
array ( [1] => 50.00 [5] => 59.38 [4] => 62.50 [2] => 62.50 [7] => 66.67 [8] => 68.75 [6] => 80.00 [9] => 91.67 ) the priority key , score value.
based on example; key 2 should above key 4 both share same value priority greater on key 2.
i hope makes sense starting uncertainty sanity this, haha.
many thanks, scott.
a little reformatting, sorting:
$helparr = array(); foreach ($yourarray $prio => $score) { $helparr[] = array($score, $prio); } sort($helparray); to format:
$yourarray = array(); foreach ($helparr $h) { $yourarray[$h[0]] = $h[1]; } php arrays sorting
Comments
Post a Comment