generate a random number between 1 and 10 in php

To generate a random number between 1 and 10 in PHP, you can use the rand() function. Here's an example:

main.php
$random_number = rand(1, 10);
echo $random_number;
51 chars
3 lines

The rand() function takes two arguments: the minimum number and the maximum number you want to generate. In this case, we set the minimum to 1 and the maximum to 10. The function will then generate a random number between 1 and 10 (inclusive), which we assign to the $random_number variable. Finally, we use echo to display the value of $random_number.

related categories

gistlibby LogSnag