To generate a random number between 1 and 10 in PHP, you can use the rand()
function. Here's an example:
main.php51 chars3 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
.
gistlibby LogSnag