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;

Masukkan email anda untuk pengumuman posting baru. Tiada posting baru, tiada email akan dihantar 🙂

Delivered by FeedBurner

Categories: PHP
Leave a comment

Leave a Reply

Required fields are marked *