In this post, i will tell you how to get random key from PHP array.
array_rand
method in PHP will return the keys of the random entries.
This method takes two argument : first will be the input array and second argument specifies how many entries you want to picked.
Each time when you refresh the page you will get different number.
Syntax :
array_rand(array,number)Example :
- <?php
- $arr = array('a','b','c','d','e','f');
- $random_key = array_rand($arr, 3);
- print_r($random_key);
- ?>