dimanche 7 février 2016

How to apply rand() or some other built-in function on an array that contains all string elements in order to randomly select a string?

I've a following array :

$family = array("Amit", "Suresh", "Vinit", "Somesh", "Sagar", "Shriram");

Now I want to randomly select a name from the above array.

How should I do this?

I know about rand() function. Even I tried rand($family); but it gave me Warning as below :

Warning: rand() expects exactly 2 parameters, 1 given in /var/www/project/index.php on line 7

It's asking for second argument.

So please someone help me in selecting a string randomly from an array that contains all string elements.

Thanks.




Aucun commentaire:

Enregistrer un commentaire