thank_you
thank_you

Reputation: 11107

Array Rand Not Randomizing

Created an array that needs randomizing however the array_rand is not working. Is my syntax wrong somewhere? I don't notice anything wrong. Plus, array_rand is used elsewhere on the code so I know it's possible to use it.

$array_11 = array (
"40","20","36",
);

$random_width_1 = array_rand($array_11, 3);

echo $array_11[$random_width_1[0]];
echo $array_11[$random_width_1[1]];
echo $array_11[$random_width_1[2]];

Upvotes: 0

Views: 894

Answers (2)

mrok
mrok

Reputation: 2710

Try to use try http://php.net/shuffle instead of array_rand

Upvotes: 3

complex857
complex857

Reputation: 20753

The problem is that array_rand sorts it's output array. if you ask exactly as much item as your input you will get all the indexes back in order. (see this comment)

If you want to create a random order of your array you can use shuffle

Upvotes: 2

Related Questions