I have a function that loads a butterfly image.
There are 3 possible parameters: colour, angle and position
The last one is always explicitly set, but the first 2, if not set, are determined with a random number. This means that the function will always load a nice randomly coloured and angled butterfly, unless specifically set.
I have this
function randombf ($randbf,$randangle,$position) {
$randbf = rand(1,4);
$randangle = rand(1,4);
echo '<div class="bf '.$position.'" style="background:url(\'images/bf_'.$randangle.'_'.$randbf.'.png\');"></div>';
}
Now the problem I have is that I would only like the random to be set if the parameters aren't passed.
Something like:
if(!$randbf) {
$randbf = rand(1,4);
}
But that doesn't work if I pass
randombf('1','2','whatever')
It performs the random regardless.
What am I doing wrong?