Monday 7 April 2014

Creating play game rolling dice in php

rolling dice
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
Screenshot1
Output (Screenshot2 , Screenshot3):-

random number in php
Screenshot2

rand function in php
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..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates