Forum Moderators: coopster
function compare ($x, $y) {
if ( $x[1] == $y[1] )
return 0;
else if ( $x[1] < $y[1] )
return -1;
else
return 1;
}
usort ($listing, 'compare');
However, I would like to set up a sorting function in which I can dynamically select which value to sort by. So I tried multiple varients of the below code, but I can't seem to get the "$i" varible to work. Is there a way around this, or a better script out there?
$i = 1; // or what ever value I selectfunction compare ($x, $y) {
if ( $x[$i] == $y[$i] )
return 0;
else if ( $x[$i] < $y[$i] )
return -1;
else
return 1;
}
usort ($listing, 'compare');
Oh and Merry Christmas!
array_multisort() [be.php.net].