Re: Re: Array Sorting Headaches

From: Date: Mon, 19 Apr 2004 12:29:42 +0000
Subject: Re: Re: Array Sorting Headaches
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-183800@lists.php.net to get a copy of this message
> > OK, so it's just the other way round - I see. Instead of deleting the entry > > with the highest expiry date we delete all the others: > > > > foreach ($foo as $key => $value) { > > > > $tempArray = array(); > > > > foreach ($value as $subkey => $subvalue) { > > > > // add expires value only to the temporary array for > > sorting > > $tempArray[$subkey] = $foo[$key][$subkey]['expires']; > > } > > > > // sort array by value descending > > arsort($tempArray); > > > > /* new stuff starts here */ > > // remove the entry with the latest expiry (the first array > > element) > > array_push($tempArray); > > > > // now unset all remaining/not needed entries > > foreach ($tempArray as $tempKey => $tempValue) { > > > > unset($foo[$key][$tempKey]); > > } > > } > > > > By the way, isn't there a way to filter this stuff BEFORE or WHILE the whole > > array is created? > > Thanks for the help. I'll give that snippet a try and see what comes out. > > The array is a result of a rather nasty SQL statement running against a > database (which I didn't design). Unfortunately, the way the database is > designed, its very difficult to extract the domain information. > > I am in the process of rewriting the entire thing as a Java application, > hopefully that will make things a bit clearer, since I'll also be > refactoring the database schema. Please let me know if it works. I'm sure there's a more elegant way to do it. > Many thanks, > Burhan You're welcome ;) Torsten

« previous php.general (#183800) next »