php sort help - sort numerical descending then by alphabetical?
Using PHP 5.x.
I would like to sort a set of values first numerically, then alphabetically. For example, here's my code so far: Code:
<?php Code:
34112:pears Code:
34112:oranges |
You want to look at usort, where it sorts using a user defined function, you will then need to write your own function that will compare the values, first comparing the number and if they are equal then compare the characters.
|
I knew this thread sounded familiar...
|
Thank you both. Yes, that was my thread. The thing is, the perl functions I ended up writing to do it (there were TWO of them that had to work together) might not work in PHP. I have to start from scratch again, it looks like. That takes time and I'm to finish this whole project this week. If I have to rewrite the functions I won't be able to finish in time. :(
So what I'll do is not have it sort the items alphabetically after values are sorted and get the rest of the project finished, and then just go back and try to work more on the alphabetical thing later. Perl and PHP are very similar (I was easily able to port another function into PHP from perl that I needed) but not everything is similar. Some things I have to do over. I was hoping that PHP already *had* a function that would take care of it without me resorting to having to re-invent the wheel all over again. |
All times are GMT -5. The time now is 10:52 AM. |