I want to make an array with a random amount of values between 2 and 5.
Each value would be 50.
What's the easiest way to do this?
eg:
$array = array(50,50,50,50)
$array = array(50,50)
I want to make an array with a random amount of values between 2 and 5.
Each value would be 50.
What's the easiest way to do this?
eg:
$array = array(50,50,50,50)
$array = array(50,50)
$array = array();
for($i = 0, $max = rand(2,5); $i < $max; $i++) $array[] = 50;
This will create an array with 2 to 5 items with the value 50.
Edit: An easier solution is to use array_fill()
:
$array = array_fill(0, rand(2, 5), 50);