Re: [PHP] ksort by value

2012-09-03 Thread John Taylor-Johnston
That works, thanks. I think I'll put this into MySQL eventually. "sort by" key would do it better, and I will need to more. Serge Fonville wrote: Sort does not maintain the association between key and value. Use asort to sort on value while maintaining the key. Kind regards/met vriendelijke

Re: [PHP] ksort by value

2012-09-03 Thread Stuart Dallas
On 3 Sep 2012, at 22:55, John Taylor-Johnston wrote: > http://php.net/manual/en/array.sorting.php is pretty clear. But my problem is > that sort ($freq) destroyed my key. Did you actually read it? There's a table on that page that summarises exactly what each sorting function does, with a colu

Re: [PHP] ksort by value

2012-09-03 Thread Serge Fonville
If you want to perform a count on all the unique values (in SQL Terms a group by and a count) use http://php.net/manual/en/function.array-count-values.php instead. Kind regards/met vriendelijke groet, Serge Fonville http://www.sergefonville.nl Convince Microsoft! They need to add TRUNCATE PART

Re: [PHP] ksort by value

2012-09-03 Thread Serge Fonville
Sort does not maintain the association between key and value. Use asort to sort on value while maintaining the key. Kind regards/met vriendelijke groet, Serge Fonville http://www.sergefonville.nl Convince Microsoft! They need to add TRUNCATE PARTITION in SQL Server https://connect.microsoft.com

Re: [PHP] ksort by value

2012-09-03 Thread John Taylor-Johnston
Sort does not work seamlessly. I have my key and sort($freq); print_r ($freq); looks like: Array ( ... [1000] => 172 [1001] => 176 [1002] => 179 [1003] => 441 ) This is what I want: Array ( ...

Re: [PHP] ksort by value

2012-09-03 Thread John Taylor-Johnston
Serge Fonville wrote: Have you looked at http://php.net/manual/en/array.sorting.php? 2012/9/3 John Taylor-Johnston > ksort($freq) sorts the array by the key. And that works fine. But I would also like to sort by value t

Re: [PHP] ksort by value

2012-09-03 Thread Serge Fonville
Hi, Have you looked at http://php.net/manual/en/array.sorting.php? Kind regards/met vriendelijke groet, Serge Fonville http://www.sergefonville.nl Convince Microsoft! They need to add TRUNCATE PARTITION in SQL Server https://connect.microsoft.com/SQLServer/feedback/details/417926/truncate-par

Re: [PHP] ksort by value

2012-09-03 Thread John Taylor-Johnston
ksort($freq) sorts the array by the key. And that works fine. But I would also like to sort by value to see which words are more frequent. There is no |ascending/descending option to ksort?| ksort sorts by key, if you want by value, look at sort. As to asc/desc sort, they just have a differen

Re: [PHP] ksort by value

2012-09-03 Thread John Taylor-Johnston
ksort($freq) sorts the array by the key. And that works fine. But I would also like to sort by value to see which words are more frequent. There is no |ascending/descending option to ksort?| ksort sorts by key, if you want by value, look at sort. As to asc/desc sort, they just have a differen

Re: [PHP] ksort by value

2012-09-03 Thread Matijn Woudt
On Mon, Sep 3, 2012 at 8:33 PM, John Taylor-Johnston wrote: > Hi, > > ... > $words = preg_split('/[[:space:]]+/',$mynewstring); > > foreach ($words as $word) { > $freq[$word]++; > } > > ksort($freq); > print_r ($freq); > ?> > > If I have my terminology right, ksort($freq) sorts the array by t

[PHP] ksort by value

2012-09-03 Thread John Taylor-Johnston
Hi, If I have my terminology right, ksort($freq) sorts the array by the key. And that works fine. But I would also like to sort by value to see which words are more frequent. There is no |ascending/descending option to ksort?| Thanks, John Array ( [] => 1 [a] => 165 [about] => 4