I have a switch built in to set variables based on a $_POST['x'];
my echo test works on all the variables but one, and i cannot seem to find out why:
switch ($jobType) {
case "pp":
$jobType = "Pick Pocket"; //echo works 'Pick Pocket'
$success = rand(1,100); //echo works - random numbers 1-100
$threshold = 0; //echo works - '0'
$money = rand(0-100); //changed to rand(0,100) and it works
echo $money;
break;
}
the echos I named work both inside the case
and outside the switch
except for $money
. Any ideas what I am missing?
UPDATED --
switching from
1-100
to1,100
worked - thanks everyone!
$money = rand(0-100);
it's not 0-100
should be 0,100
I believe you use the rand function incorrectly. Try replacing the dash with a coma:
$money = rand(0, 100);
From php.net: int rand ( int $min , int $max )
Also you might wanna check what value you're actually getting. I don't believe it's an integer:
$money = rand(0-100);
var_dump($money);
I get NULL in this case and a warning: WARNING rand() expects exactly 2 parameters, 1 given...
functionality of rand() function given below hope you can understand the confusion
int rand ( int $min , int $max )
min:: The lowest value to return (default: 0)
max:: The highest value to return (default: getrandmax())
Return Values:: A pseudo random value between min (or 0) and max (or getrandmax(), inclusive).
Example:
<?php
echo rand() . "
";
echo rand() . "
";
echo rand(5, 15);
?>
The above example will output something similar to:
7771
22264
11