Q:

sort Array in specific filename order

How do I sort the following data in the order I want it?
The array:
array(4)
{ 
[21]=> string(7) "2-2.pdf" 
[22]=> string(7) "2-3.pdf"
[23]=> string(7) "2-4.pdf" 
[24]=> string(5) "2.pdf" 
} 

I want this sort:
2.pdf
2-2.pdf
2-3.pdf
2-4.pdf

A:

Yes you could use usort in this case:
$array = [21=> "2-2.pdf", 22=> "2-3.pdf", 23=> "2-4.pdf",24=> "2.pdf", ];
usort($array, function($a, $b){
    $a = str_replace('-', '', $a);
    $b = str_replace('-', '', $b);
    return $a - $b;
});

