How to randomly select elements from an array?

I have an array of 50 elements, and I would like to select 5 of them randomly and return an array. Is there a function for this?

+3
source share
2 answers

Put the elements in an array and use:

$selectrand = array_rand($arrayname, 5);
+7
source

Try the following:

$randomnumber = (rand()%$num);
-2
source

Source: https://habr.com/ru/post/1711623/


All Articles