Re: Multisorting an array
| From: | Kevin Stone | Date: | Mon, 17 Feb 2003 21:01:13 +0000 |
| Subject: | Re: Multisorting an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135894@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: "Joachim Krebs" <docuk@gmx.net>
To: <php-general@lists.php.net>
Sent: Monday, February 17, 2003 8:25 AM
Subject: [PHP] Multisorting an array
> I have an array with the following structure:
>
> Array
> (
> [0] => Array
> (
> [name] => images
> [type] => dir
> )
>
> [1] => Array
> (
> [name] => includes
> [type] => dir
> )
>
> [2] => Array
> (
> [name] => index.php
> [type] => file
> )
>
> [3] => Array
> (
> [name] => index.tpl.php
> [type] => file
> )
>
> [4] => Array
> (
> [name] => lib
> [type] => dir
> )
> }
>
> I want to array_multisort this array so it becomes sorted by type
> first, and then by name. What are the arguments for the function in
> this case?
>
> Joachim
I do not believe there are any arguments to the array_multisort() functon
that will help you in this case. Sometimes you just need to backup and try
to see the problem in a new light. Instead of building a large
multi-dimensional array you might consider building two one-dimensional
arrays (one for files and one for directories). That solves half of your
problem right there. Then all you need to do is sort each array using
asort() and you can combine them or print them out in whatever order you
like.
- Kevin