Get Random Element From Array using PHP

array_rand function

<?php

$data = [10, 3, 17, 50, 15];
$key = array_rand($data);
$element = $data[$key];

echo $element;

Leave a Comment

Cancel reply

Your email address will not be published.