Partial Sort ?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
if I have an array of ten items how can I sort the first five items in
the array without sorting the second five items?  

Re: Partial Sort ?

contained the following:

Quoted text here. Click to load it

Use a loop to copy first five  to a temporary array, sort that array and
then replace into original using array_splice()
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs

Re: Partial Sort ?

comatose wrote:

Quoted text here. Click to load it

By using an user-defined sorting function.


You'll need to do some dirty tricks in that function to keep track of how
many items you have sorted, to not sort those, but that should be the way..

Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org- ; ;

Re: Partial Sort ?

lovely and talented comatose broadcast on comp.lang.php:

Quoted text here. Click to load it

Try searching the function index of manual for 'array' --- I'm pretty sure
you will find some useful slices of information to splice into your
knowledge base.

Lars Eighner     < <
                         Countdown: 580 days to go.
  Owing to googlegroups not screening users to eliminate spammers and other
         USENET abusers, I do not see most posts from googlegroups.

Re: Partial Sort ?

On Jun 20, 3:18 am, comatose wrote:
Quoted text here. Click to load it

$array = array('c', 'b', 'a', 'q', 's', 'r', 'h', 'p');
$head = array_slice($array, 0, 5);
$newArray = array_merge($head, array_splice($array, 5));

I believe someone mentioned this...

Site Timeline