PHP Programing language

array_rand() Function in PHP
Previous Home Next

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.

Syntax:
array_rand(array,number)

In above syntax, "array" specifies an array and "number" specifies how many random keys to return

Example:

<?php
$a=array("Apple","Banana","Orange","Mango","Guava");
$random_keys=array_rand($a,3);
echo $a[$random_keys[0]]."<br>";
echo $a[$random_keys[1]]."<br>";
echo $a[$random_keys[2]];
?>

Output:

Apple
Banana
Guava

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: