Hi,
please post some more code (especially the part of the code that creates that array).
As a first step I'd suggest to change the line
$temparray = ksort($temparray);
Add two lines so that it looks like ...
print_r($temparray);
$temparray = ksort($temparray);
print_r($temparray);
The two additional lines print the array in a human readable way.
The error message in most cases means that $temparray isn't an array.
Thomas