![rolling dice rolling dice](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgQPbc4M19_yIZAsBVOn5dbcCtPKziovAFk5ybEwHS6V_3w7KMYsHe7hp7GywKTvk5of5NNvLicnqukrk9SLw1WFDt0vzoACCd4vGNH2b_PyMxI1tc-1XSxcBVail5zc6YKRmvEe19vK_J/s1600/rolling-dice.jpg) |
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>
![rolling dice in php rolling dice in php](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8ErzlvWtOpan5TVuFQ1080phOFUImkf4a5eFMURAyXFSbg4WaYFYPRoL-XHPyt_sL234ga4ePRZYhXKM_gKSQ2ijjgj7K44gYjkBJlxMI6cDcDhkP19-YmX5LW9Wid8K0g1zenua37XhI/s1600/Creating+play+game+rolling+dice+in+php+(Screenshot1).PNG) |
Screenshot1 |
Output (Screenshot2 , Screenshot3):-
![random number in php random number in php](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDhOQRVX1yQXxPfAabgflIA8cqnHWya1QXzP7P0-Kstm3zNVoN0U8_2t-fZqjRvqasWX-HIOvlN00ozvu2Bn32aG4lAfydZ61IZ8KTHFt7mhZzQRsOOfaD-MbTS5Q2XVPwKYScp0SJaal0/s1600/Creating+play+game+rolling+dice+in+php+(Screenshot2).PNG) |
Screenshot2 |
![rand function in php rand function in php](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2z_-sAD1C7GRv8EhjoOvR3gzqBdSiXKMCJGWZPDd93Vt08rEFK8YSyBDrCKh6IT27Tg5xYjQBJCYhf3HY9zeG0T5nb2tW6kx3ldKxc-2nLpwbEmRFOd49AlcVMXlQ52ybQt2oetPDpTpQ/s1600/Creating+play+game+rolling+dice+in+php+(Screenshot3).PNG) |
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..