Shalom!
Es geht um Farbtausch. Wer sichs ansehen möchte, möge doch bitte auf satanick.de vorbeischauen.
Ich habe die wechselnden Farben, die sich nicht wiederholen, jetzt mal so gelöst:
PHP-Code:
$farbe=array("<font color="#FF0000">","<font color="#C0C0C0">","<font color="#00FF00">");
$rand2=rand(0,count($farbe)-1);
If ($rand2==2)
{
$color1=$farbe[$rand2];
IF (rand(0,1)==1)
{
$color2=$farbe[$rand2-1];
$color3=$farbe[$rand2-2];
}
ELSE
{
$color2=$farbe[$rand2-2];
$color3=$farbe[$rand2-1];
}
}
ELSEIF ($rand2==1)
{
$color1=$farbe[$rand2];
IF (rand(0,1)==1)
{
$color2=$farbe[$rand2-1];
$color3=$farbe[$rand2+1];
}
ELSE
{
$color2=$farbe[$rand2+1];
$color3=$farbe[$rand2-1];
}
}
ELSEIF ($rand2==0)
{
$color1=$farbe[$rand2];
IF (rand(0,1)==1)
{
$color2=$farbe[$rand2+1];
$color3=$farbe[$rand2+2];
}
ELSE
{
$color2=$farbe[$rand2+2];
$color3=$farbe[$rand2+1];
}
$color2=$farbe[$rand2+1];
$color3=$farbe[$rand2+2];
}
Die Farben werden dann natürlich mit echo $color1."text", $color2."text" usw aufgerufen.
Damit kommt immer eine eindeutige, zufällige Zuweisung der Farben zustande, ohne daß sie sich wiederholen. Funzt auch. Aber es scheint mir für so ein verhältnismäßig einfaches Problem zuviel Code - ich bin kein Php Crack, weiß daher vielleicht jemand eine elegantere Lösung? Problematisch ist auch, daß meine Lösung sehr starr und auf 3 Farben festgelegt ist - kommen mehr Farben hinzu, läuft das ins schier Unendliche wegen der vielen Kombinationsmöglichkeiten.