How to generate random number in PHP?

Sometimes we need to have a random quote, news, testimonials being displayed on the front page of a website. We can use random number function to get a random id of a data to be generated.

The code is as below

——

$maxnum = 10;
srand(time());
$random_num = (rand()%$maxnum);
echo “The random number is: ” . $random_num;