PHP Random collection of element from an array

We can randomly collect one or more element from an array by using array_rand() function in PHP. We can specify the number of random elements required by specifying an optional parameter in side the function.


echo "First random element = ".$value[$rand_keys[0]];
echo "<br>Second random element = ".$value[$rand_keys[1]];
We can create a six digit random number generator which will give us only characters.

srand ((double) microtime() * 10000000);
$input = array ("A", "B", "C", "D", "E","F","G","H","I","J","K","L","M","N","O","P","Q",
$rand_index = array_rand($input,6);
print $input[$rand_index[3]];
print $input[$rand_index[5]];
print $input[$rand_index[4]];
print $input[$rand_index[2]];
print $input[$rand_index[1]];
print $input[$rand_index[0]];
By using above code we can generate 6 digit random number of only characters. You can read how to generate random numbers here.
Read here how to generate random password string having alphabets and digits
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net



    Very nice script

    Post your comments , suggestion , error , requirements etc here .

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2023 All rights reserved worldwide Privacy Policy Disclaimer