note 56814 added to function.usort

From: Date: Thu, 15 Sep 2005 18:53:57 +0000
Subject: note 56814 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-95245@lists.php.net to get a copy of this message
gk at lka dot hu: I've removed a few errors and moved both functions into one. The line with the prefix-check did'nt work right. <?php function CompareUmlaut($astring, $bstring) { $ALP = "AaÁáBbCcDdEeÉéFfGgHhIiÍiJjKkLlMmNnOoÓóÖöÕõPpQqRrSs" . "TtUuÚúÜüÛûVvWwXxYyZz0123456789!?.()[]=%+-" // find first differing char $aLen = strlen($astring); $bLen = strlen($bstring); for ($i=0; $i<$aLen && $i<$bLen && $astring[$i]==$bstring[$i]; $i++); // if one string is the prefix of the other one, the shorter wins if ($i == $aLen || $i == $bLen) return (strlen($astring) < strlen($bstring)) ? -1 : 1; // otherwise depends on the first different char $ALPL = strlen($ALP); $ap = $bp = -1; $j = 0; while (($j < $ALPL) && (($ap == -1) || ($bp == -1))) { if ($ALP[$j] == $astring[$i]) $ap = $j; if ($ALP[$j] == $bstring[$i]) $bp = $j; $j++; } return($ap < $bp) ? -1 : 1; ?> ---- Manual Page -- http://www.php.net/manual/en/function.usort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56814 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56814&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56814&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56814&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56814&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56814&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56814&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56814&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56814&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95245) next »