How to get random value from an array PHP

I am explaining you, How to get random value in from an array PHP. we can use the shuffle() function in PHP to randomly shuffle the order of values in an array.

<?php
  $list = array(11, 12, 13, 14, 15, 16);
   
  shuffle($list);
  foreach ($list as $value){
    echo "$value" . "<br>";
  }
?>

Result:

12
16
14
11
13
15

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 61 = 62