The rand() function has two parameters: the lower limit for a random number and the upper limit. You cannot use such variables because this is not how the function works.
Take a look at the documentation:
http://php.net/rand
A simple way to achieve what you want:
$array = array(); $array[0] = 'banana'; $array[1] = 'orange'; $randomSelected = $array[rand(0,(count($array)-1))];
As far as I read, this solution is faster than array_rand() . I see if I can find the source of this.
source share