Pequeno desafio
Foi pena só ler agora o desafio do Dustin Diaz mas de qualquer forma aqui está a minha solução despretensiosa obtida em cerca de 20 min. É engraçado como há tantas soluções para um problema.
Numa side note ora aí está um excelente link bait ![]()
/*In English: Group together all duplicate items that occur anytime beyond twice by wrapping them with a tag, naturally “bookending” them.
Simple, right? No, really. Tease your brain for a few minutes, you can fix that bug after lunch.*/
$polvero = array('a','b','c','d','e','e','e','e','e','f','e','f','e','f','a','a','a','f','f','f');
foreach($polvero as $key=>$value){
if($twice==true and !array_key_exists(1,$twice)){
$string.=$starttag.$value;
}else{
$string.=$endtag.$value;
}
if($polvero[$key-1]==$value && $polvero[$key+1]==$value){
$twice[]=true;
$starttag='<span>';
}elseif($twice==true){
$endtag='</span>';
if(array_key_exists($key+1,$polvero)){
$twice=false;
}else{
$twice=false;
$end=true;
}
}else{
$endtag=false;
}
}
if($end==true){$string.='</span>';}
echo $string;

Sou o João José tenho 29 anos (tou velho...) sou webmaster há 5 anos e a tempo inteiro aí há 3 anos. Vou tentanto escrever aqui qualquer coisa de útil e de tempos a tempos revelar umas pérolas :-)