Cheers for the input guys, I'm assuming that as 2 of suggested sorting the array that even in numeric arrays they remain in set order. I'm manually assigning keys in the while loop so count() is no good for me.
Chris, I didn't know you could send an array to max(), so I tried
$keys = implode (', ', array_keys($array));
$max = max($keys);
But you can't use a string.