How to get a random value from array in PHP?

If you don't mind picking the same item again at some other time then you can use following code:
   <?php
   $items = array(1,5);
   echo $items[rand(0, count($items) - 1)];
?>
It will display a random number from the elements of array. 1 or 3 or 5 or 1 .......

Comments

Popular Posts