|
Posted by Erwin Moller on 02/07/06 10:55
christiang@lateral.net wrote:
> Hi guys I'd like to sort a multidimensional array that hasn't numerical
> index, in fact it is like:
>
> Array
> (
> [mobile] => Array
> (
> [name_str] => mobile
> [relationCount_int] => 1
> )
>
> [video] => Array
> (
> [name_str] => video
> [relationCount_int] => 2
> )
>
> [flash] => Array
> (
> [name_str] => flash
> [relationCount_int] => 1
> )
>
> [tool] => Array
> (
> [name_str] => tool
> [relationCount_int] => 1
> )
>
> )
>
> And I'd like to sort, for instance for the value of
> "relationCount_int", so the new order should be something like:
>
> Array
> (
> [video] => Array
> (
> [name_str] => video
> [relationCount_int] => 2
> )
> [mobile] => Array
> (
> [name_str] => mobile
> [relationCount_int] => 1
> )
>
>
> [flash] => Array
> (
> [name_str] => flash
> [relationCount_int] => 1
> )
>
> [tool] => Array
> (
> [name_str] => tool
> [relationCount_int] => 1
> )
>
> )
>
> Any idea? I tried some script I found on php.net but didn't work. The
> could should run inside a class method.
>
> Thanks a lot, chr
Hi
Yes, it is easy if you use uksort().
-----------------------------------
uksort
(PHP 3 >= 3.0.4, PHP 4, PHP 5)
uksort -- Sort an array by keys using a user-defined comparison function
-----------------------------------
Read more here:
http://nl2.php.net/manual/en/function.uksort.php
Regards,
Erwin Moller
Navigation:
[Reply to this message]
|