1

I woud like to sort an array which typically includes names and email addresses. The problem is that the email addresses appear last even though they may start with 'a'

e.g.

$myarray = ("Alex Mayfeild", "David Beckham", "Oliver Twist", "[email protected]", "[email protected]", ........) //and so on

Upon sorting the array using php's sort function "[email protected]" will appear close to the end even though the functionality I would like to achieve is for him to appear after Alex.

natcasesort and natsource functions based on natural ordering seem to fail. Correction: natcasesource works it returns true when working as stated in docs. Thanks @meagar

Is there anyway to achieve the requested functionality. Thanks for any help guys. It is very much appreciated.

1
  • @KalpeshMehta isn't that mostly for associative arrays? Commented Aug 2, 2012 at 21:54

2 Answers 2

2

sort() is case sensitive, as it sorts based on the letters ASCII value.

Try natcasesort(), if you want too "sort an array using a case insensitive 'natural order' algorithm".

Sign up to request clarification or add additional context in comments.

1 Comment

Does case sensitive natural order take into account the @ and .s?
-1

Seems to me that sort($myarray, SORT_STRING|SORT_FLAG_CASE); should sort the array the way you want.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.