I would choose to use only numerical data for the size, then you're sql can do the work for you.
The problem is simply string comparisons. To get around this, you'll need to write you're own code and use usort to make use of it.
I don't know what you're array's look like so I can only speculate.
PHP Code:
function cmp($a, $b)
{
$result = 0;
$tmpIntA = null;
$tmpIntB = null;
if (!is_array($a) || !is_array($b) || !isset($a['size']) || isset($b['size']))
{
throw new Exception('One of the entries does not contain the correct data!');
}
$tmpIntA = int_val($a['size']);
$tmpIntB = int_val($b['size']);
if ($tmpIntA == $a['size'] && $tmpIntB == $b['size'])
{
$result = $tmpIntA - $tmpIntB;
}
else
{
$result = strcmp($a['size'], $b['size']);
}
return $result;
}
usort($aYourStack, 'cmp');
Either way you're going to have problems since you're mixing strings with numbers - comparing (string(10) with string(small)) is tricky. The above cmp function trys to cast you're input to numbers, compares the numbers with the original strings to see if they are considered the same, and if they are it compares based on integer math. Otherwise it does a string comparison.
You're best bet is to simply use numbers. No clue if the above actually works though.