Forum Moderators: coopster
Each word gets hashed to an integer value, and it's useful for me to have the values in the array ordered by their string length (in ascending order) to do this.
After a gander through the array functions in the PHP manual the closest match I see to this is uasort(array,function cmp_function)
Would this be the right function to use? And if it is, any idea what the function would look like to get them in ascending order of length...
$allwords = array("whatever","goes","in","here");
function Ascii_Sort($val_1, $val_2)
{
// initialize the return value to zero
$retVal = 0;
// compare lengths
$firstVal = strlen($val_1);
$secondVal = strlen($val_2);
if($firstVal > $secondVal)
{
$retVal = 1;
}
else if($firstVal < $secondVal)
{
$retVal = -1;
}
return $retVal;
}
uasort($allwords, "Ascii_Sort");
foreach($allwords as $val)
{
print "$val <BR>";
}