Re: [PHP] Multi-Sort -- how to do this?

2009-06-20 Thread tedd
At 3:36 PM -0400 6/18/09, Robert Cummings wrote: tedd wrote: At 1:45 PM -0400 6/18/09, Robert Cummings wrote: Thanks to Rob and Daniel for also playing, better luck next time. :-) - note smiley -- I do appreciate your time. Mine version retains key associations. It wasn't a complete waste of

RE: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread Ford, Mike
On 17 June 2009 22:12, tedd advised: Hi gang: Here's the problem. Let's say you have a collection of arrays, such as: $a = array(); $b = array(); $c = array(); $d = array(); And then you populate the arrays like so: while(...) { $a[] = ... $b[] = ... $c[] =

Re: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread Robert Cummings
Ford, Mike wrote: On 17 June 2009 22:12, tedd advised: Hi gang: Here's the problem. Let's say you have a collection of arrays, such as: $a = array(); $b = array(); $c = array(); $d = array(); And then you populate the arrays like so: while(...) { $a[] = ... $b[] = ...

RE: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread Bob McConnell
From: Ashley Sheridan On Wed, 2009-06-17 at 19:27 -0400, tedd wrote: At 10:54 PM +0100 6/17/09, Ashley Sheridan wrote: I'd probably go with some sort of custom bubble sorting function. Base the sorting on your $d array, and then update the other arrays as necessary. Should be OK if they all

RE: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread Bob McConnell
From: Ashley Sheridan On Wed, 2009-06-17 at 19:27 -0400, tedd wrote: At 10:54 PM +0100 6/17/09, Ashley Sheridan wrote: I'd probably go with some sort of custom bubble sorting function. Base the sorting on your $d array, and then update the other arrays as necessary. Should be OK if they all

Re: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread Daniel Brown
On Thu, Jun 18, 2009 at 05:11, Ford, Mikem.f...@leedsmet.ac.uk wrote: array_multisort($d, $a, $b, $c) should do what you want, That'll actually hit it right on the head, too, Mike. My example from last night sorted and combined the arrays to be keyed and sortable by $d --- which,

RE: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread tedd
At 10:11 AM +0100 6/18/09, Ford, Mike wrote: On 17 June 2009 22:12, tedd advised: -snip- Now, let's say you want to sort the $d array, but you also want the arrays $a, $b, and $c to be arranged in the same resultant order as $d. For example, please follow this: Before sort of $d: $a

Re: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread tedd
Ash: You missed the point. I could use the built-in sort (i.e., sort() ) and sort the $d array. However, I would like the indexes of the other arrays to match the new sort. Cheers, tedd I think I might need a for-instance here, as you lost me! Thanks Ash Ash: You can sort any

Re: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread Robert Cummings
tedd wrote: At 10:11 AM +0100 6/18/09, Ford, Mike wrote: On 17 June 2009 22:12, tedd advised: -snip- Now, let's say you want to sort the $d array, but you also want the arrays $a, $b, and $c to be arranged in the same resultant order as $d. For example, please follow this: Before

Re: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread tedd
At 1:45 PM -0400 6/18/09, Robert Cummings wrote: Thanks to Rob and Daniel for also playing, better luck next time. :-) - note smiley -- I do appreciate your time. Mine version retains key associations. It wasn't a complete waste of time. Cheers, Rob. Rob: Nothing you provide me is a

Re: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread Robert Cummings
tedd wrote: At 1:45 PM -0400 6/18/09, Robert Cummings wrote: Thanks to Rob and Daniel for also playing, better luck next time. :-) - note smiley -- I do appreciate your time. Mine version retains key associations. It wasn't a complete waste of time. Cheers, Rob. Rob: Nothing you provide me

Re: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread Ashley Sheridan
On Thu, 2009-06-18 at 13:04 -0400, tedd wrote: Ash: You missed the point. I could use the built-in sort (i.e., sort() ) and sort the $d array. However, I would like the indexes of the other arrays to match the new sort. Cheers, tedd I think I might need a

Re: [PHP] Multi-Sort -- how to do this?

2009-06-17 Thread Ashley Sheridan
On Wed, 2009-06-17 at 17:11 -0400, tedd wrote: Hi gang: Here's the problem. Let's say you have a collection of arrays, such as: $a = array(); $b = array(); $c = array(); $d = array(); And then you populate the arrays like so: while(...) { $a[] = ... $b[] = ...

Re: [PHP] Multi-Sort -- how to do this?

2009-06-17 Thread Douglas Temple
...Sticking my neck out playing with the big boys (and girls) now... I assume you've looked at array_multisort() for this, I would think you could have multiple arrays being sorted with it (I've only ever used it for 2-array sorts). The other option would be to pop all those arrays into a single

Re: [PHP] Multi-Sort -- how to do this?

2009-06-17 Thread Ashley Sheridan
On Wed, 2009-06-17 at 22:54 +0100, Douglas Temple wrote: ...Sticking my neck out playing with the big boys (and girls) now... I assume you've looked at array_multisort() for this, I would think you could have multiple arrays being sorted with it (I've only ever used it for 2-array sorts).

Re: [PHP] Multi-Sort -- how to do this?

2009-06-17 Thread tedd
At 10:54 PM +0100 6/17/09, Ashley Sheridan wrote: I'd probably go with some sort of custom bubble sorting function. Base the sorting on your $d array, and then update the other arrays as necessary. Should be OK if they all have the same index, like in your example. If you were using keys, could

Re: [PHP] Multi-Sort -- how to do this?

2009-06-17 Thread Ashley Sheridan
On Wed, 2009-06-17 at 19:27 -0400, tedd wrote: At 10:54 PM +0100 6/17/09, Ashley Sheridan wrote: I'd probably go with some sort of custom bubble sorting function. Base the sorting on your $d array, and then update the other arrays as necessary. Should be OK if they all have the same index,

Re: [PHP] Multi-Sort -- how to do this?

2009-06-17 Thread Daniel Brown
On Wed, Jun 17, 2009 at 17:11, teddt...@sperling.com wrote: Hi gang: [snip!] Is there a slick way to do that? Hacked together in the two minutes before I go to bed, so don't complain about its inelegance. ;-P ?php $a = array('apple', 'banana', 'grape', 'orange'); $b = array(100, 2111,

Re: [PHP] Multi-Sort -- how to do this?

2009-06-17 Thread Robert Cummings
tedd wrote: Hi gang: Here's the problem. Let's say you have a collection of arrays, such as: $a = array(); $b = array(); $c = array(); $d = array(); And then you populate the arrays like so: while(...) { $a[] = ... $b[] = ... $c[] = ... $d[] = ... } Now, let's say you want

Re: [PHP] Multi-Sort -- how to do this?

2009-06-17 Thread Paul M Foster
On Wed, Jun 17, 2009 at 10:31:18PM -0400, Robert Cummings wrote: snip ?php function tedd_sort( $arrays ) { $master = null; $followers = array(); $first = true; foreach( array_keys( $arrays ) as $key ) { if( $first ) { $first = false;