array_rand

The array_rand() function returns a random key from an array, or it returns an array of random keys if you specify that the function should return more than one key.

Example

<?php
 $array = array("PHP", "ASP", "JSP");
 $keys = array_rand($array, 2);
 echo $array[$keys[0]];
 ?>

Output

PHP

Share