How would I set PHP to randomly chose between these two sets of variables to use:
$key = goop;
$john = heck yeah;
and this
$key = roop;
$john = reck reah;
Thanks ever so much! :)
For example:
if ( rand(0,1) )
{
$key = "goop";
$john = "heck yeah";
}
else
{
$key = "roop";
$john = "reck reah";
}
rand() is an int, so it should be even chanceI'd recommend using an array:
$selection = array(
array('goop', 'heck yeah'),
array('roop', 'reck reah')
);
shuffle($selection);
list($key, $john) = array_pop($selection);
$selection. It'll support as many as you want to add inlist is a function -- it assigns the array values to the variables $key and $johnStore the values in an array, and then use rand() to generate the values:
$key_vals = array('goop', 'roop', 'toop');
$john_vals = array('heck yeah', 'reck reah', 'leck leah');
$key = $key_vals[rand(0, (count($key_vals) - 1))];
$john = $john_vals[rand(0, (count($john_vals) - 1))];
You can easily extend this by adding values to the respective arrays, and increasing the maximum random number (i.e. second argument in rand()).
goop with heck yeah) it'd be better to use Martin's answer.