1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <?php
// Fonction de comparaison
function fn_tri_mp3($a, $b) {
$a=str_replace(".mp3","",$a);
$b=str_replace(".mp3","",$b);
$a=str_replace("selection","",$a);
$b=str_replace("selection","",$b);
$a=str_replace("-",".",$a);
$b=str_replace("-",".",$b);
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
$array [0] = "selection0.mp3";
$array [1] = "selection1-2.mp3";
$array [2] = "selection1.mp3";
$array [3] = "selection2.mp3";
$array [4] = "selection10.mp3";
print_r($array);
echo "<br/>";
// Trie et affiche le tableau résultant
uasort($array, 'fn_tri_mp3');
print_r($array);
?> |
Partager