How can I sort a array like this by its keys, from the smaller resolution to the larger one:
$sizes = array(
'120x120' => 'large',
'60x60' => 'small',
'200x200' => 'very large',
'90x90' => 'medium',
...
?
should be:
ksort()
in numeric mode should work just fine :
$sizes = array(
'120x120' => 'large',
'60x60' => 'small',
'200x200' => 'very large',
'90x90' => 'medium',
);
ksort($sizes, SORT_NUMERIC);
var_dump($sizes);
will get you :
array
'60x60' => string 'small' (length=5)
'90x90' => string 'medium' (length=6)
'120x120' => string 'large' (length=5)
'200x200' => string 'very large' (length=10)