I'm currently working on a school project about php. The task is to design a website with some php navigation, a calculator, a truthsayer and some other functions. Now, I have a problem with the truthsayer I would like to get some help with. The truthsayer is a php randomizer that prints out a "truth" from an array I've set up. The truthsayer also prints out different amounts of truths depending on what number I give it. For example: If I type "3" into a box and presses enter, it will post three truths.
Now the problem: Since it completely randomizes it's output, I tend to get the same truths after each other. I for example ask for 10 truths, and 4-5 of them are the same as one of the other truths. Therefore I was wondering if anyone had an idea on how to make it avoid posting the same truth over and over again. Someone I know suggested a temporary removal of the truth from the array, but I'm not sure how I will make that work.
Any ideas? Much appreciated=P
My code:
<html>
<body>
<div id="Sannsigar">
<?php
if(isset($_POST["psc"])) {
$adder1 = $_POST["i1"];
$SannOutput= "";
$Val = array("1=Ichi","2=Ni","3=San","4=Shi/Yon","5=Go","6=Roku","7=Nana","8=Hachi","9=Kyu","10=Jyu");
switch ($adder1) {
case "1" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
"<br>";
break;
}
case "2" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
break;
}
case "3" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
break;
}
case "4" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
break;
}
case "5" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
break;
}
case "6" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
break;
}
case "7" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
break;
}
case "8" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
break;
}
case "9" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
break;
}
case "10" : {
for ($x=1; $x<=$adder1; $x++)
{
echo $Val[array_rand($Val)] . "<br>"; }
break;
}
default: {
Echo "FEIL! Feil inndata. Oppgje eit tal mellom 1 og 10.";
break;
}
}
$Footer = fopen("Sannsigar/footer.php", "w");
fwrite ($Footer, "$adder1 sanning(ar) fr� Birger AS" . "<br>");
fclose($Footer);
}
?>
</div>
</body>
</html>