I have an array like this
//$src
Array(
[dim_55] => path/to/image.jpg
[dim_180] => path/to/image.jpg
[dim_190] => path/to/image.jpg
[dim_475] => path/to/image.jpg
[dim_635] => path/to/image.jpg
[dim_540] => path/to/image.jpg
[dim_1130] => path/to/image.jpg
[dim_1900] => path/to/image.jpg
)
( path/to/image.jpg
is a generic path )
I would like to order this by key
in an order like
dim_1900
dim_1130
dim_635
dim_540
dim_475
..
To achieve this solution I did something like:
$sortSrc = array();
foreach($src as $key => $value){
$newkey = explode("dim_", $key);
$sortSrc[$newkey[1]] = $value;
}
krsort($sortSrc);
It works but maybe is not so effective. Is there a way in which I can achieve this with native PHP
functions?