In this tutorial, we are going to see how to get random value from an array in PHP. You can use the PHP shuffle() function to randomly shuffle the order of elements or values in an array. The shuffle() function returns FALSE on failure.
How to get random value from an array in PHP
<?php
$nbrs = array(1, 2, 3, 4, 5, 6);
// Randomize the order of elements in the array
shuffle($nbrs);
foreach ($nbrs as $value){
echo "$value" . "<br>";
}
?>
Output:
6
2
5
3
4
1