omg
omg

Reputation: 139862

How to randomly choose items from an array ?

I have an array of 50 items and I would like to choose 5 of them randomly and get an array back. Is there a function for this?

Upvotes: 3

Views: 867

Answers (2)

George Claghorn
George Claghorn

Reputation: 26535

Put the items in an array and use:

$selectrand = array_rand($arrayname, 5);

Upvotes: 7

Secko
Secko

Reputation: 7716

Try this:

$randomnumber = (rand()%$num);

Upvotes: -2

Related Questions