[PHP] Re: Sorting an array

2011-03-01 Thread David Robley
Ron Piggott wrote: I need help to know how to sort the words / phrases in my array. Variable name: $words_used print_r( $words_used ); Current output: Array ( [187] = Sin [249] = Punished [98] = Sanctuary [596] = Sing [362] = Anointing Oil ) Desired result: Alphabetical sort: Array (

Re: [PHP] Re: Sorting an array

2011-03-01 Thread FeIn
Also check http://www.php.net/manual/en/function.natsort.php On Tue, Mar 1, 2011 at 1:39 PM, David Robley robl...@aapt.net.au wrote: Ron Piggott wrote: I need help to know how to sort the words / phrases in my array. Variable name: $words_used print_r( $words_used ); Current output:

Re: [PHP] Re: Sorting an array

2011-03-01 Thread Alex
That or do it in mysql before you get the data back, its also pretty good at sorting, you know ;) -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. FeIn aci...@gmail.com wrote: Also check http://www.php.net/manual/en/function.natsort.php On Tue, Mar 1, 2011 at 1:39 PM,

[PHP] Re: Sorting multidim array and keeping associations

2004-12-11 Thread Peter Lauri
Stupid as I was, I did not do what I should have done :) In the origin the array was created from a MySQL database. I did not sort it correctly from there because I did not have the knowledge about the GROUP BY command, so I tried to solve it via PHP. Now I have everything sorted and alright just

[PHP] Re: Sorting multidim array and keeping associations

2004-11-18 Thread Sebastian Mendel
Peter Lauri wrote: I have an multidim array that looks something like this: [40] = [1]=32, [2]=55, [total]=87 [22] = [8]=2, [7]=105, [total]=107 [142] = [2]=3, [7]=8, [total]=11 I want to sort this array according to the total and still keep the acc. with the basekey. I know I can easily do this

[PHP] Re: Sorting multidim array and keeping associations

2004-11-18 Thread Peter Lauri
The problem was more complex than I described, I instead wrote a sorting algorithm for this specific purpose. The array multi-dim array looks like this (short version). The total element is just the sum of the other. This is a point system for golftournaments. I wanted to sort them first on total

[PHP] Re: Sorting multidim array and keeping associations

2004-11-18 Thread Sebastian Mendel
Peter Lauri wrote: The problem was more complex than I described, I instead wrote a sorting algorithm for this specific purpose. The array multi-dim array looks like this (short version). The total element is just the sum of the other. This is a point system for golftournaments. I wanted to sort

[PHP] Re: Sorting multidim array and keeping associations

2004-11-17 Thread Sebastian Mendel
Peter Lauri wrote: Best groupmember, I have an multidim array that looks something like this: [40] = [1]=32, [2]=55, [total]=87 [22] = [8]=2, [7]=105, [total]=107 [142] = [2]=3, [7]=8, [total]=11 I want to sort this array according to the total and still keep the acc. with the basekey. I know I

[PHP] Re: Sorting multidim array and keeping associations

2004-11-17 Thread Peter Lauri
I have tried to figure it out how to use it with those, but I can not find a solution. - Best Of Times /Peter Sebastian Mendel [EMAIL PROTECTED] skrev i meddelandet news:[EMAIL PROTECTED] Peter Lauri wrote: Best groupmember, I have an multidim array that looks something like this:

[PHP] Re: Sorting multidim array and keeping associations

2004-11-17 Thread Peter Lauri
I have tried to figure it out how to use it with those, but I can not find a solution. - Best Of Times /Peter Sebastian Mendel [EMAIL PROTECTED] skrev i meddelandet news:[EMAIL PROTECTED] Peter Lauri wrote: Best groupmember, I have an multidim array that looks something like this:

[PHP] Re: sorting multidimensional array by a second level value

2004-09-17 Thread Jasper Howard
the way i did this was by structuting the array like this $array['href'][0] = 'www.com.com'; $array['description'][0] = 'blah!'; etc... then use the array_multisort function like this To sort by href: array_multisort($array['href'],$array['description'],$array['time']); a key point is that the

[PHP] Re: Sorting an array by value length.

2003-10-22 Thread Justin Patrin
You want to use usort, which lets you specify a comparison function. function cmpByLength($a, $b) { return strlen($a) strlen($b); } usort($arrayToSort, 'cmpByLength'); And change the '' to '' if the ordering is wrong. Rolf Brusletto wrote: Hey all - I've been scouring the php.net site for a

[PHP] Re: sorting multi-array

2003-07-24 Thread sven
hi, try usort(); ciao SVEN JiøîÆèî eË wrote: hello, i have got a problem, tehere is an array: $x = array( array(15,55,array(1,2,3),3,5,array(1,2,5)), array(25,55,array(1,2,3),3,5,array(1,2,5)), array(5,55,array(1,2,3),3,5,array(1,2,5)) ); and I need to sort this arraybz

[PHP] Re: Sorting an array

2001-09-16 Thread ~~~i LeoNid ~~
On Thu, 13 Sep 2001 11:10:03 +0200 impersonator of [EMAIL PROTECTED] (_lallous) planted I saw in php.general: here's your script, .. Kill 'em All The Wall; $mem = split(\n, $mem); Explode() is less expensive then split(), as long as you don't use regexp, which is the case here, and (from the

[PHP] Re: Sorting an array

2001-09-13 Thread _lallous
here's your script, ? $mem = The Childhood A Man called lallous The Long kiss good night Abbey Road Dark Side Of the Moon The Final Cut The Zombie A Hard Days Night Kill 'em All The Wall; $mem = split(\n, $mem); $arr1 = array(); for ($i=0;$icount($mem);$i++) { $line = trim($mem[$i]);

[PHP] Re: Sorting an array

2001-09-13 Thread _lallous
another case-insensitive version: pre ? $mem = The childhood A Man called lallous The Long kiss good night Abbey Road Dark Side Of the Moon The Final Cut The Zombie A Hard Days Night Kill 'em All The Wall; $mem = split(\n, $mem); $arr1 = array(); for ($i=0;$icount($mem);$i++) { $line =