PHP array random value array_rand

Returns a set of keys for random entries of array. If you want to pick all entries in a randomized fashion you should be using:

//Get array value out from array random
//example random 4 array 
$randValues = array_intersect_key($input, array_flip(array_rand($input, 4)));

# pick a random key in your array:
$rand_key = array_rand($your_array);

# extract the corresponding value:
$rand_value = $your_array[$rand_key];

# remove the key-value pair from the array:


By Keenlio, September 5, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

4 − two =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>