RE: [PHP] Perl to PHP code tranlation URGENT !

From: Date: Tue, 08 Aug 2000 19:19:05 +0000
Subject: RE: [PHP] Perl to PHP code tranlation URGENT !
Groups: php.general 
Request: Send a blank email to php-general+get-10756@lists.php.net to get a copy of this message
(For those who aren't familiar Perl, that contorted Perl syntax sorts the @categName list elements and stores the result in @categAlpha. The $# construct references the number of elements in the @categName array, and the cmp operator performs a custom sort based on each array element value.) PHP has a built in functions to sort arrays, eliminating the custom sort that you do using sort and the cmp operator. Check the various array sorting functions at http://www.php.net/manual/ref.array.php. In your case, you can just use the sort() function, so you'd do this: $categAlpha = sort($categName); PHP can also do custom sorts, just like Perl's sort {} syntax. Take a look at usort() in the manual for details. --Bruce Bruce Christensen Intel Corporation brucex.r.christensen@intel.com -----Original Message----- From: Javier Leyba [mailto:jleyba@sabueso.net] Sent: Tuesday, August 08, 2000 12:05 PM To: php-general@lists.php.net Subject: [PHP] Perl to PHP code tranlation URGENT ! Hi All ! I'm doing a code tranlation from Perl to a new PHP Aplication and I don't know how to did the following: I've an array called categName with categories extracted from a MySQL database and the Perl code do: @categAlpha = sort { $categName[$a] cmp $categName[$b] } (0 .. $#categName); How could I do the same with PHP ? TAre there a similar sort function on PHP ? Thanks in advance ! 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

« previous php.general (#10756) next »