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", "ant.stev@wherever.com", "peter.pan@neverland.com", ........) //and so on
Upon sorting the array using php’s sort function “ant.stev@wherever.com” 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.
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”.