mardi 2 juin 2015

How to get random item from array only from the specified keys (e.g x key first)

I have a array that i want to select two item as random, And two keys are selected between the key 2 and the key 10.

$arr = array=(1,2,3,4,5,6,7,8,9,10,11,12);

I can get two random item:

$rand_keys = array_rand($arr, 2);

$arr[$rand_keys[0]]; // one
$arr[$rand_keys[0]]; // two

But in this case, It is possible that selected items be from the entire array. Now i want to know how can I limit my choice ?




Aucun commentaire:

Enregistrer un commentaire