|
Rolling Dice in php |
Creating dice game were we want use how to roll a dice randomly. In this example we will use rand function to generate random number between 1 to 6 by supplying argument in rand function. As you may see my tutorial for
random number generate in Php for more info on rand function
Code for Creating play game rolling dice in php (Screenshot1):-
<?php
if (isset($_POST['roll'])) {
$rand = rand(1, 6);
echo 'You rolled a '.$rand;
}
?>
<form action="index.php" method="POST">
<input type="Submit" name="roll" value="Roll dice">
</form>
|
Screenshot1 |
Output (Screenshot2 , Screenshot3):-
|
Screenshot2 |
|
Screenshot3 |
As you can see playing rolling dice script in php. We created form with submit button when ever user clicks submit button with will generate random number with rand function with two argument such as 1 which is lower limit it will not show less then one number and upper limit is 6 it will not echo out more then 6 number value as you seen dice it only contains number 1 to 6.
No comments:
Post a Comment
Thanks For Comment Will get you Soon..