note 21033 added to function.natcasesort

From: Date: Thu, 25 Apr 2002 23:55:25 +0000
Subject: note 21033 added to function.natcasesort
Groups: php.notes 
Request: Send a blank email to php-notes+get-29859@lists.php.net to get a copy of this message
add this loop to the function above if you want items which have the same first characters to be listed in a way that the shorter string comes first. -------------------- /* short before longer (e.g. 'abc' should come before 'abcd') */ for($i=count($array)-1;$i>0;$i--) { $str_a = $array[$i ]; $str_b = $array[$i-1]; $cmp_a = strtolower(substr($str_a,0,strlen($str_a))); $cmp_b = strtolower(substr($str_b,0,strlen($str_a))); if ($cmp_a==$cmp_b && strlen($str_a)<strlen($str_b)) { $array[$i]=$str_b; $array[$i-1]=$str_a; $i+=2; } } -------------------- -- http://www.php.net/manual/en/function.natcasesort.php http://master.php.net/manage/user-notes.php?action=edit+21033 http://master.php.net/manage/user-notes.php?action=delete+21033 http://master.php.net/manage/user-notes.php?action=reject+21033

« previous php.notes (#29859) next »