For starters, the function is supposed to return 0 for countries that
are equal.
As it stands now, it's going to return 1 / -1 randomly based on which
arg happens to be $a versus $b.
That's bad.
For some implementations of shuffle/sort routines, it will actually
crash.
I forget which implementa
weetat wrote:
> Hi all ,
>
> I have array value as shown below, i have paste my test php code below:
> I have problem when doing usort() when 'country' = '', i would like to
> display records where country = '' last. Any ideas how to do that ?
> ...
You might try searching the list's archive's.
Sent: Monday, July 31, 2006 1:57 PM
To: php-general@lists.php.net
Subject: Re: [PHP] sorting in array
At 10:31 PM 7/30/2006, weetat wrote:
> I have problem when doing usort() when 'country' = '', i would
> like to display records where countr
; 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 th
At 01:14 AM 7/31/2006, weetat wrote:
Thanks Paul,
Very weird tried Peter's option, it doesn't work.
Btw , how to sort by ascending ?
Please explain what you mean. The current script DOES sort ascending
by country (except for the blank country fields which are placed at the end):
http:
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
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'] == '') ? "zzz" : $a['country'];
$country2 = ($b['country'] == '') ? "zzz" : $b['country'];
return ($count
At 05:40 PM 7/30/2006, Peter Lauri wrote:
function cmpcountry($a, $b)
{
$country1 = $a['country'];
$country2 = $b['country'];
if($country1=='') return 1;
else return ($country1 < $country2) ? -1 : 1;
}
Good call, Peter; my suggestion was unne
At 10:31 PM 7/30/2006, weetat wrote:
I have problem when doing usort() when 'country' = '', i would
like to display records where country = '' last. Any ideas how to do that ?
...
$arraytest= array(
array
(
'country' => '',
)
,
array
(
Hi ,
Doesn't work .
Any ideas ?
Thanks
Peter Lauri wrote:
function cmpcountry($a, $b)
{
$country1 = $a['country'];
$country2 = $b['country'];
if($country1=='') return 1;
else return ($country1 < $country2) ? -1 : 1;
}
-Original Messa
function cmpcountry($a, $b)
{
$country1 = $a['country'];
$country2 = $b['country'];
if($country1=='') return 1;
else return ($country1 < $country2) ? -1 : 1;
}
-Original Message-
From: weetat [mailto:[EMAIL PROTECTED]
Sent: Monday, July
11 matches
Mail list logo