Page 1 of 1
Sorting an array by a keys value in the array
Posted: Tue Oct 09, 2007 6:35 am
by impulse()
I have an array that has a layout:
$array[0][0] = "Something";
$array[0][1] = 20;
$array[1][0] = "Something else";
$array[1][1] = 50;
Is there an existing funtion to sort descending by the numeric value?
Posted: Tue Oct 09, 2007 6:40 am
by VladSun
Can you show us the expected result? I'm not sure I understand you.
Posted: Tue Oct 09, 2007 6:47 am
by impulse()
No problem:
I'd want key 1 of the array to be top of the list because 50 is the higher value and array key 0 to be bottom of the list because it's the lower number. I'll add some more values so it's more understandable.
Before sort:
Code: Select all
$array[0][0] = "Something";
$array[0][1] = 20;
$array[1][0] = "Something else";
$array[1][1] = 50;
$array[2][0] = "Something else again";
$array[2][1] = 13;
$array[3][0] = "Last time";
$array[3][1] = 400;
After sort:
Code: Select all
$array[3][0] = "Last time";
$array[3][1] = 400;
$array[1][0] = "Something else";
$array[1][1] = 50;
$array[0][0] = "Something";
$array[0][1] = 20;
$array[2][0] = "Something else again";
$array[2][1] = 13;
If there are still problems understanding then let me know.
Posted: Tue Oct 09, 2007 6:54 am
by VladSun