|
Posted by Ewoud Dronkert on 11/26/05 22:34
Peter J Ross wrote:
> be able to sort the resulting two-dimensional array of matches by one
> column only, leaving the other columns unsorted.
Does the ordering of the other columns not matter and do you just want to
avoid doing extra work, or does it specifically need to be left exactly
the way it went in?
If the former, just use usort with your own comparison function:
$col = 2; //set to right column number to sort on
function cmp($a, $b) {
global $col;
return strcmp($a[$col], $b[$col]); //or a numerical comparison perhaps
}
usort($myTwoDimensionalArray, 'cmp');
If the latter, you'll have to write your own (relatively) low-level
sorting routine because the order of identical elements is not defined for
built-in sorting routines, ie. you can't rely on them to just leave those
elements in their existing order. (unless stated thusly in the manual..).
--
E. Dronkert
Navigation:
[Reply to this message]
|