|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-07-12 08:53 UTC] admin at finance-on dot net
[2002-07-12 08:56 UTC] sander@php.net
[2002-09-11 11:36 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 05:00:01 2025 UTC |
i am sorting an array of strings using uasort($a,'isoCompare'). the user function isoCompare, in its recursive variant, crashes randomly. first, the support function charPower which remaps diacritical chars... this one is ok. function charPower ($ch,$charPowerCaseSensitive=FALSE,$charPowerReverseOrder=FALSE) { $power = 0; $char = ($charPowerCaseSensitive ? $ch : strtoupper($ch)); switch (ord($char)) { case 232: $power = 10*ord(($charPowerCaseSensitive ? "c" : "C") case 200: $power = 10*ord("C")+3; break; case 190: $power = 10*ord(($charPowerCaseSensitive ? "z" : "Z") case 174: $power = 10*ord("Z")+5; break; case 185: $power = 10*ord(($charPowerCaseSensitive ? "s" : "S") case 169: $power = 10*ord("S")+5; break; case 230: $power = 10*ord(($charPowerCaseSensitive ? "c" : "C") case 198: $power = 10*ord("C")+6; break; case 240: $power = 10*ord(($charPowerCaseSensitive ? "d" : "D") case 208: $power = 10*ord("D")+5; break; default: $power = 10*ord($char); } return ($charPowerReverseOrder ? ((-1)*$power) : $power); } ; now the recursive isoCompare... function isoCompare ($s1,$s2) { $len1 = strlen($s1); $len2 = strlen($s2); if ($len1==0 || $len2==0) { $ret = $len1 - $len2; if (!$ret) return 0; else return $ret > 0 ? +1 : -1; } ; $c1 = charPower($s1); $c2 = charPower($s2); $power1 = charPower($c1) ; $power2 = charPower($c2) ; if ($power1==$power2) { $ret = isoCompare(substr($s1,1), substr($s2,1)); return $ret; } else { $ret = $power1-$power2; return $ret > 0 ? +1 : -1; } } the iterative version works fine: function isoCompare ($s1, $s2) { global $isadmin; $i = 0; $ret = 0; while (!$ret) { $len1 = strlen($s1); $len2 = strlen($s2); if ($len1 == 0 && $len2 == 0) $ret = 0; elseif ($len1 == 0) $ret = 1; elseif ($len2 == 0) $ret = -1 ; else { $power1 = charPower(substr($s1,0,1)) ; $power2 = charPower(substr($s2,0,1)) ; if ($power1 > $power2) $ret = 1; elseif ($power2 > $power1) $ret = -1; else { $s1 = substr($s1,1); $s2 = substr($s2,1); } ; } ; } ; // while return $ret; } ; my setup: ./configure \ --with-config-file-path=/usr/local/lib \ --with-zlib \ --with-mysql=/usr/local/mysql \ --with-exec-dir=/usr/local/safe_mode --enable-track-vars=yes \ --enable-magic-quotes=yes --disable-debug \ --with-pdflib \ --with-xml \ --with-sablot=/usr/local/lib \ --with-expat=/usr/local/lib \ --enable-sysvsem \ --enable-sysvshm \ --with-gd \ --with-iconv \ --with-curl=/usr/local/curl \ --with-apxs=/usr/local/apache/bin/apxs