In your particular instance a bubblesort will do, as Bill suggested.
Bubblesort means going through all the elements in the array from back to front (or front to back, whichever you happen to do)
or swapping the elements in the array whenever you find that they are not in the right order.
contider this array (single value) that I want to sort in numerical order, lowest first.
9
3
4
6
2
7
A bubblesort will start with the 6th element, 7.
It will compare that to the 5th element , 2.
element 5 is lower than element 6, so nothing happens.
Now we move to element 4 and 5, values 6 and 2.
6 is definately bigger than 2, so we swap them.
9
3
4
2
6
7
now we look at elements 3 and 4, values 4 and 2.
4>2, so we swap them
9
3
2
4
6
7
Now look at elements 2 and 3, values 3 and 2
3>2 so swap
9
2
3
4
6
7
See the 2 moving \"bubbling\" up to the top of the array?
And did you notice the 6 moving down?
As you can see, it will take more than one iteration to get the 9 fro the top to the bottom.
You will need to repeat the process untill all elements are sorted.
How do you know they are sorted?
They are sorted when you go through all elements and don\'t swap any of them.
So, set a flag at the beginning, something like $done=no;
Make a loop: while($done=no);
first thing you do inside the loop, is $done=yes; to stop your procedure from going on forever.
Now go through the sort routine once,
In the swap-elements code, add a command to change the flag to $done=no.
Get the idea?
good luck!