To Get Random Values from Array :
$arr = array("a"=>"apple","b"=>"ball","c"=>"cat","d"=>"dog" );
shuffle($arr);
Eg :
Before Shuffle :
Array ( [a] => apple [b] => ball [c] => cat [d] => dog )
After Shuffle :
Array ( [0] => ball [1] => cat [2] => apple [3] => dog1 ) // will change order every time we refresh the page
To Pick Random Key from Array :
Eg : picking 2 random keys from an array
$val = array_rand($arr,2);
print_r($val);
Array ( [0] => b [1] => d )
$arr = array("a"=>"apple","b"=>"ball","c"=>"cat","d"=>"dog" );
shuffle($arr);
Eg :
Before Shuffle :
Array ( [a] => apple [b] => ball [c] => cat [d] => dog )
After Shuffle :
Array ( [0] => ball [1] => cat [2] => apple [3] => dog1 ) // will change order every time we refresh the page
To Pick Random Key from Array :
Eg : picking 2 random keys from an array
$val = array_rand($arr,2);
print_r($val);
Array ( [0] => b [1] => d )