Web Design and Development Forums

Need help sorting an array

This is a discussion on "Need help sorting an array" within the PHP Forum section. This forum, and the thread "Need help sorting an array are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > PHP Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 16th, 2008, 20:00   #1 (permalink)
Junior Member
 
Join Date: Oct 2007
Location: UK
Posts: 38
Need help sorting an array

I have an array that contains values like _img_1.png, _img_2.png, _img_3.png, Back.png. How can I sort them so that they appear in this order? I've tried sort() and natsort() but Back.png is always appearing at the start of the array.
djeyewater is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 17th, 2008, 00:23   #2 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 517
Blog Entries: 4
Re: Need help sorting an array

its because of the underscore in front of the image names. PHP counts that in sorting.
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 17th, 2008, 01:10   #3 (permalink)
Rob
Head Admin & CEO
 
Rob's Avatar
 
Join Date: Jul 2003
Location: bug busting new style
Age: 34
Posts: 3,311
Blog Entries: 7
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: Need help sorting an array

make a temporary array... loop through the array and make another array with all items that dont begin with an underscore.... either remove those items from the initial array or make a new array with just underscored items.

Sort both the arrays independantly. Treat the array with underscores as 'first' and the other last.
__________________
Rob Collyer - SEO Specialist (8 years+)
Owner & Founder of Webforumz.com

My Mrs's site:- Student Midwife Forums

I am currently unavailable for private work
-------------------------------------------------
Rob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 17th, 2008, 08:28   #4 (permalink)
Junior Member
 
Join Date: Oct 2007
Location: UK
Posts: 38
Re: Need help sorting an array

Thanks for the replies, I thought that an underscore would come before a letter. Is there a list anywhere of how php prioritises characters when performing a sort?
djeyewater is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 18th, 2008, 15:05   #5 (permalink)
Junior Member
 
Join Date: Apr 2007
Location: Kansas
Age: 18
Posts: 33
Send a message via AIM to BRONIC
Re: Need help sorting an array

Quote:
Originally Posted by djeyewater View Post
Thanks for the replies, I thought that an underscore would come before a letter. Is there a list anywhere of how php prioritises characters when performing a sort?

<a href="http://www.asciitable.com"> The Ascii Table </a>

is how php distinguishes values of characters.
BRONIC is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 18th, 2008, 15:07   #6 (permalink)
Junior Member
 
Join Date: Apr 2007
Location: Kansas
Age: 18
Posts: 33
Send a message via AIM to BRONIC
Re: Need help sorting an array

asciitable SRRY
BRONIC is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 18th, 2008, 15:16   #7 (permalink)
Junior Member
 
Join Date: Oct 2007
Location: UK
Posts: 38
Re: Need help sorting an array

That's great, thanks!
djeyewater is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Array sorting welshstew ASP Forum 6 Nov 28th, 2007 16:45
Sorting a PHP array fallen_angel PHP Forum 3 Apr 20th, 2007 22:18
Sorting a new array from an existing array Ozeona Flash & Multimedia Forum 2 Sep 20th, 2005 08:43
array unable to check another array so as to be displayed Ozeona Flash & Multimedia Forum 1 Aug 5th, 2005 10:26
Sorting the array - reversing the sequence codes? Ozeona Flash & Multimedia Forum 1 Aug 3rd, 2005 01:52



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 11:07.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59