To generate a random number between 1 and 100 in PHP, you can use the rand()
function. The rand()
function returns a random integer within a specified range. By default, rand()
returns a random number between 0 and the maximum value that can be represented by an integer.
To limit the range to 1-100, we will pass those values as arguments to the rand function:
main.php50 chars3 lines
The above code will generate a random integer between 1 and 100 and store it in the $randomNumber
variable. Then, it will print the value of the $randomNumber
variable using the echo
statement.
gistlibby LogSnag