You are here: Re: Sort array without index « PHP Programming Language « IT news, forums, messages
Re: Sort array without index

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация