J'ai essayé ça:
<?php
function countNb($position_courante,$t){
$i=0;
$courant = $t[$position_courante];
while (($t[$position_courante] == $courant)){
$res[0] = ++$i;
$res[1] = ++$position_courante;
$res[2] = $courant;
}
return $res;
}
$tab = array('0'=> 'A', '1'=> 'A', '2'=> 'A', '3'=> 'B', '4'=> 'B', '5'=> 'C', '6'=> 'A', '7'=> 'A');
$borne_sup = count($tab);
$position = 0;
$i = 0;
while ($position < $borne_sup){
$res = countNb($position,$tab);
$position = $res[1];
$resultat[$i] = 'Il y a '.$res[0].' '.$res[2];
$i++;
}
echo '';
print_r($resultat);
echo '
';
?>
Résultat:
Array
(
[0] => Il y a 3 A
[1] => Il y a 2 B
[2] => Il y a 1 C
[3] => Il y a 2 A
)
*****
THINK ->
SEEK -> ASK