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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| <?php
$l =Array(1, 1, 3, 2, 2, 4, 5, 5, 3, 3,3, 1, 4,1, 5,1, 1, 3, 3, 3);
function orderListe($arr,$p,$s){
if(count($arr)>0){
$e=array_count_values ($arr);
arsort($e);
$index=0;
$stopOne = true;
foreach ($e as $k => $v){
for ($i=0;$i< $v ;$i++){
$d[] = $k ;
}
if(!isset($s[0]) && $stopOne == true ){
$index = 0 ;
$stopOne = false;
$p = $v;
}
else if($v>$index && $p != $v && $stopOne == true && isset($s[0]) && $s[count($s)-1]!=$k ){
$index = $k;
$stopOne = false;
$p = $v;
}
}
$key= array_search($index,$d);
if( isset($d[$key]) ){
$s[] = $d[$key];
unset($d[$key]);
return orderListe($d,$p,$s);
}
}
else{
return($s);
}
}
$liste=orderListe($l,0,array());
for ($i=0;$i<count($liste);$i++){
echo $liste[$i].",";
}
echo "<br/>";
?> |
Partager