Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Sorting specific array dimension
Old 09-16-2008, 05:45 AM Sorting specific array dimension
RadGH's Avatar
Skilled Talker

Posts: 76
Name: Radley
Trades: 0
The PHP manual is confusing me as far as sorting arrays goes. Heres the array I have set up, and I'd like to sort it based on the 'ext'. I refer to these like $files[12]["ext"] = "jpg"

Code:
Array
(
    [0] => Array
        (
            [name] => Empire.JPG
            [path] => ./files/Empire.JPG
            [size] => 191.01 kb
            [ext] => JPG
            [url] => localhost/wwwexplore/files/Empire.JPG
        )

    [1] => Array
        (
            [name] => Contact.gif
            [path] => ./files/Contact.gif
            [size] => 5.62 kb
            [ext] => GIF
            [url] => localhost/wwwexplore/files/Contact.gif
        )
...
)
I tried doing array_multisort($files["ext"]) but it says arg#1 must be an array. I'm not really sure how to sort this.

--Edit:

Code:
function cmp($a, $b)
{
    return strcmp($a["ext"], $b["ext"]);
}

printf(usort($files, "cmp"));
From the PHP manual, this has been bothering me for a long time but finally found it.

Last edited by RadGH; 09-16-2008 at 05:54 AM..
RadGH is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-16-2008, 08:28 AM Re: Sorting specific array dimension
Super Spam Talker

Latest Blog Post:
PSD Squirrel Launched
Posts: 932
Trades: 7
hi there,

a bit confused about what your doing - or trying to do...

you wish to sort by the ext... or group by them?

if your sorting by them.. is it alphabetically? - anyway, just sort() will do sorting by ext for you... http://php.net/sort

sounds more like your trying tyo group them though? let me know, we see what we can do ..
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Sir P is offline
Reply With Quote
View Public Profile Visit Sir P's homepage!
 
Reply     « Reply to Sorting specific array dimension
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10003 seconds with 12 queries