Re: help with sort problem

From: Date: Sun, 12 May 2002 17:27:00 +0000
Subject: Re: help with sort problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-97226@lists.php.net to get a copy of this message
On Monday 13 May 2002 00:23, Nick Wilson wrote: > Hi all, > I hope someone might help me with a little puzzle... > > I have bunch of db results and one of the fields is 'name', > I want to see if there are 2 parts to it like FirstName LastName and if > so order by the last name. > > I can see explode() being the php function I need here but am a little > lost as to what will happen if there is only one word in the name var. > > If someone can suggest what I might do that would be great! > many thanks... Not knowing exactly what it is you want I'm assuming the following: if there is a lastname use that in the sort, otherwise use the firstname. Thus your sorted list will look something like: Bryan Adams (Adams, Bryan) Arnold Brian John Butcher (Butcher, John) If that is what you want then: while (names) { explode the name if there is more than one element swap it, then join add this processed name onto a new array } use one of the array sort functions to sort the new array. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Wagner's music is better than it sounds. -- Mark Twain */

« previous php.general (#97226) next »