I have an array called $ran = array(1,2,3,4);
I need to get a random value out of this array and store it in a variable, how can I do this?
I have an array called $ran = array(1,2,3,4);
I need to get a random value out of this array and store it in a variable, how can I do this?
Another approach through flipping array to get direct value.
Snippet
array_rand
return key not value. So, we're flipping value as key.Note: PHP key alway be an unique key, so when array is flipped, duplicate value as a key will be overwritten.