Multi-sorting arrays ...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have been trying to get an array to sort on a particular column and
have been having problems with my main key ...

array_multisort($dirlist["dirname"], SORT_DESC, SORT_STRING);

This function takes an array ($dirlist) which has been loaded with a
directory listing where each directory has its own index number
("dirid") and displays the listing in descending order by name
("dirname").  This works fine for the sorting of the names but the index
number is reallocated (I assume because it is numeric) and I lose my
link to the directory.  arrgghh!

How can I keep the rows 'together' and make sure that the index number
and the name remain consistant?

Any tips or snippets of syntax would be a great help.

Alan Searle.

Re: Multi-sorting arrays ...

Alan Searle wrote:
Quoted text here. Click to load it

I've never used array_multisort() and I don't want to dive into the docs
right now.

Do you really need array_multisort() ?

uasort($dirlist, 'cmp_function');


function cmp_function($lhs, $rhs) {
  if ($lhs['column'] < $rhs['column']) return 1;
  return ($lhs['column'] == $rhs['column']) ? 0 : -1;

USENET would be a better place if everybody read:   | to email me: use |   | my name in "To:" |     | header, textonly |                    | no attachments.  |

Re: Multi-sorting arrays ...

Quoted text here. Click to load it

Site Timeline