-5
$szam[1]=rand(1,95);
$szam[2]=rand(1,95);

if($szam[1]!=$szam[2]){
$szam[3]=rand(1,95);

    if($szam[3]!=$szam[2]and $szam[3]!=$szam[1]){
    $szam[4]=rand(1,95);

        if($szam[4]!=$szam[3]and$szam[4]!=$szam[2]and$szam[4]!=$szam[1]){
        $szam[5]=rand(1,95);

            if($szam[5]!=$szam[4]and$szam[5]!=$szam[3]and$szam[5]!=$szam[2]and$szam[5]!=$szam[1]){
                $lottoszam=$szam[1].",".$szam[2].",".$szam[3].",".$szam[4].",".$szam[5];
            }
            else{$szam[5]=rand(1,95);}
        }
        else{$szam[4]=rand(1,95);}
    }
    else{$szam[3]=rand(1,95);}
}
else{$szam[2]=rand(1,95);}
3
  • 1
    Change the variable $szam to $s. Boom, shorter code! Commented Feb 25, 2016 at 22:45
  • This question is too vague. What do you mean by short this php code? Tell us what this code is doing, and why you want it shorter. Commented Feb 25, 2016 at 22:47
  • similar question here: stackoverflow.com/questions/7792816/php-unique-random-numbers - trying to find random unique numbers. Commented Feb 25, 2016 at 22:53

1 Answer 1

2

You can achieve this by using in_array() function. PHP Manual in_array() funcion

Save your random numbers in array and check it like this

if (in_array($random, $numbers)) {
  //exist
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.