- <?php
-
- function cmp($ar1, $ar2){
-
- $ar1 = array(strtoupper(str_replace(strrchr($ar1, '.'), '', $ar1)), strtoupper(strrchr($ar1, '.'))); //on scinde le nom de fichier et l'extension
- $ar2 = array(strtoupper(str_replace(strrchr($ar2, '.'), '', $ar2)), strtoupper(strrchr($ar2, '.')));
-
- if($ar1[1] > $ar2[1]){
- return 1;
- }
- elseif($ar1[1] === $ar2[1]){
- strcmp($ar1[0], $ar2[0]);
- }
- else {
- return -1;
- }
- }
-
- function tri($array){
-
- usort($array, 'cmp');
- return $array;
- }
-
-
-
-
- //exemple d'utilisation :
-
- $fichier = array('3.jpg', '1.bmp', '7.dot', '5.dot');
- $fichier = tri($fichier);
- print_r($fichier);
-
- ?>
<?php
function cmp($ar1, $ar2){
$ar1 = array(strtoupper(str_replace(strrchr($ar1, '.'), '', $ar1)), strtoupper(strrchr($ar1, '.'))); //on scinde le nom de fichier et l'extension
$ar2 = array(strtoupper(str_replace(strrchr($ar2, '.'), '', $ar2)), strtoupper(strrchr($ar2, '.')));
if($ar1[1] > $ar2[1]){
return 1;
}
elseif($ar1[1] === $ar2[1]){
strcmp($ar1[0], $ar2[0]);
}
else {
return -1;
}
}
function tri($array){
usort($array, 'cmp');
return $array;
}
//exemple d'utilisation :
$fichier = array('3.jpg', '1.bmp', '7.dot', '5.dot');
$fichier = tri($fichier);
print_r($fichier);
?>