Re: array.sorting.php
| From: | John Taylor-Johnston | Date: | Tue, 04 Sep 2012 17:38:31 +0000 |
| Subject: | Re: array.sorting.php | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318986@lists.php.net to get a copy of this message | ||
David OBrien wrote:
On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston <jt.johnston@usherbrooke.ca <mailto:jt.johnston@usherbrooke.ca>> wrote:Ok, let's approach this question differently. Right now the frequency of each word is in value. How do I put the frequency of each word in the key? I'm fuzzy when it comes to arrays. I can do this is MySQL. All I need is an id and two varchars and then I know how to sort any way I want. But I am processing dynamic text files. MySQL is not an option; data changes too much. PHP is faster and more efficient. I'm just no good at arrays. Here is my code: ---------------snip------------------- $mynewstring = "http://foo.com/bigtextfile.txt"; $words = preg_split('/[[:space:]]+/',$mynewstring); foreach ($words as $word) {Hi, Sorting question. http://www.php.net/manual/en/array.sorting.php I'm using ksort, which sorts like this. I don't want to use strolower. Is there a function/switch in one of the sort functions where I could get another aphabetical sort?http://www.php.net/manual/en/array.sorting.php has a lot of options. I,m not sure which one I should choose.This is what I get:LABRADOR CITY LACOSTA LARGE Labrador Labrador City Labrador Sea Lacosta Large labrador labrador sea lacosta largeThis is what I want:LABRADOR Labrador labrador LABRADOR CITY Labrador City Labrador Sea labrador sea LACOSTA Lacosta lacosta LARGE Large largenatsort natcasesort I'm sorting the key. It doesn't work. ksort is the only choice I have, right?
$freq[$word]++;} #natcasesort($freq); ksort($freq); John