RE: [PHP] sorting in array
| From: | Peter Lauri | Date: | Mon, 31 Jul 2006 03:49:26 +0000 |
| Subject: | RE: [PHP] sorting in array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-239899@lists.php.net to get a copy of this message | ||
And this for DESCending
function cmpcountry($a, $b)
{
$country1 = $a['country'];
$country2 = $b['country'];
if($country1=='' OR $country2=='') {
if($country1==$country2) return 0;
elseif($country1=='') return 1;
else return -1;
} else return ($country1 < $country2) ? 1 : -1;
}
-----Original Message-----
From: weetat [mailto:weetat.yeo@cxrus.com]
Sent: Monday, July 31, 2006 3:15 PM
To: php-general@lists.php.net; Paul Novitski
Cc: php-general@lists.php.net
Subject: Re: [PHP] sorting in array
Thanks Paul,
Very weird tried Peter's option, it doesn't work.
Btw , how to sort by ascending ?
Thanks
Paul Novitski wrote:
> At 12:22 AM 7/31/2006, Paul Novitski wrote:
>> I could make that last statement just a bit simpler:
>>
>> function cmpcountry($a, $b)
>> {
>> $country1 = ($a['country'] == '') ? "zzzzzzz" :
>> $a['country'];
>> $country2 = ($b['country'] == '') ? "zzzzzzz" :
>> $b['country'];
>>
>> return ($country1 > '' && $country1 < $country2) ? -1 : 1;
>> }
>
>
> *Sigh* I shouldn't post this late at night. This is the comparison
> function that works for me:
>
> function cmpcountry($a, $b)
> {
> $country1 = ($a['country'] == '') ? "zzzzzzz" :
> $a['country'];
> $country2 = ($b['country'] == '') ? "zzzzzzz" :
> $b['country'];
>
> return ($country1 < $country2) ? -1 : 1;
> }
>
> demo: http://juniperwebcraft.com/test/sortTest.php
> code: http://juniperwebcraft.com/test/sortTest.txt
>
> Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php