This should be incredibly easy, my only excuse is that I haven't slept in >24 hours.
Anyways, I have an array of buckets, each of which is an array of strings.
I want to sort each bucket by the number of words in the string, lower to greater
I've replicated the functionality I wish to produce in the following test code:
$bucketArray;
$bucketArray[3][] = 'four words a a';
$bucketArray[3][] = 'two words';
$bucketArray[3][] = 'one';
$bucketArray[3][] = 'three words a';
$bucketArray[1][] ='a a a a a a';
$bucketArray[1][] ='a a a a';
$bucketArray[1][] ='a a a a a';
$bucketArray[1][] ='a a';
$bucketArray[1][] ='a a a';
$bucketArray[1][] ='a';
function cmp($str1, $str2)
{
return sizeof(explode(' ', $str1)) - sizeof(explode(' ', $str2));
}
foreach($bucketArray as $bucket)
{
usort($bucket, 'cmp');
}
print_r($bucketArray);
Apparently the array is left entirely unchanged when I look at the print_r.
Someone want to point where my error is =)?