# Change to Specific Set of Values Upon Refresh

1. Change to Specific Set of Values Upon Refresh
I can't use rand() because I want to set a variable based on 2 or 3 specific values. For example, I would like to set \$BUTTS to the value of '5', '46', or '100' as an eample. The rand won't work because I don't want every value between 5 and 100.

Something like this. Any idea how this could be accomplished in php?

\$BUTTS = 5
..page refresh..
\$BUTTS = 100
..page refresh..
\$BUTTS = 46
..page refresh..
\$BUTTS = 100
..page refresh..
\$BUTTS = 5

2. I'm still at the beginner level with PHP, but my first thought was to define ranges, and then set \$BUTTS to a value based on the range returned by rand(). So, say, get a rand() value between 1 and 100, and:

if (\$value >= 1 && \$value <=33)
\$BUTTS = 5;

if (\$value >= 34 && \$value <=66)
\$BUTTS = 46

if (\$value >= 67 && \$value <=100)
\$BUTTS = 100

Would that work? There's probably a function that will choose between given values, maybe using an array, but I don't know what it is

3. Have you tried RAND(5,100)? That will return a random number between 5 and 100 (inclusive).

4. But I don't want every number between 5 and 100.

5. How about this - you can do rand(1,x), where x is the number of choices you want. Then, you can do a switch based on the numbers returned. That would probably be easier than what I first posted.

6. Ok, I got it working as needed. Thanks.

7. You need to set \$BUTTS as an array.

\$range=var(5,46,100)
\$BUTTS=\$array()

Something along those lines. I'm not proficient enough at php to code it from memory but that should be enough to search some of the php forums and find a sample you can use.

8. My bad. I totally missed the "don't" in your original post.

9. Originally Posted by MichaelColey