RE: [PHP] URGENT HELP WITH PERL CODE, PLEASE !!!!
| From: | Christensen, BruceX R | Date: | Wed, 09 Aug 2000 18:33:32 +0000 |
| Subject: | RE: [PHP] URGENT HELP WITH PERL CODE, PLEASE !!!! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-10975@lists.php.net to get a copy of this message | ||
You can also do this this way (a direct translation of the Perl code, using
a custom sort):
$categAlpha = range(0,count($categName)-1);
usort($categAlpha, custom);
function custom($a,$b) {
global $categName;
if ($categName[$a] == $categName[$b]) {
return 0;
} elseif ($categName[$a] > $categName[$b]) {
return 1;
} else {
return -1;
}
}
Perl's much shorter :).
--Bruce
Bruce Christensen
Intel Corporation
brucex.r.christensen@intel.com
-----Original Message-----
From: Javier Leyba [mailto:jleyba@sabueso.net]
Sent: Wednesday, August 09, 2000 10:58 AM
To: php-general@lists.php.net
Subject: [PHP] URGENT HELP WITH PERL CODE, PLEASE !!!!
Hi All !
Please HELPPPPP !!!
I'm translating a Perl code to a PHP code and I 've and array of names
(extracted froma MySQL database) something like this:
$categName[0] = "Ziggy";
$categName[1] = "Andy";
$categName[2] = "Ian";
$categName[3] = "Peter";
....
The Perl code call a sort function on this way:
$categAlpha = sort { $categName[$a] cmp categName[$b] } (0..$#categname);
and I get the following:
$categAlpha[0] = 1;
$categAlpha[1] = 2;
$categAlpha[2] = 3;
$categAlpha[3] = 0;
As you can see the perl sort function make a sort on the categName array by
name and return and ordered array of the original ID's on the cateAlpha
array.
I could not found a PHP function capable of do the some.
Could somebody help me ?
Thanks,
Javier
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net