Home >Backend Development >PHP Tutorial >PHP simulation dice implementation code

PHP simulation dice implementation code

小云云
小云云Original
2018-03-30 13:22:132561browse

This article mainly shares with you the implementation code of PHP simulated dice, mainly in the form of code, hoping to help everyone.

<?PHP  
$sum=0;
$num=rand(1,6);
$sum=$sum+$num;//前进步长
while ($num==6){
$num=rand(1,6);//模拟骰子的投掷
$sum=$sum+$num;//作为前进步长
};
echo "while例子执行完毕,前进:".$sum."<br  />";
$sum=0;
do{
$num=rand(1,6);
$sum=$sum+$num;
}while ($num==6);
echo "do...while 的例子执行完毕,前进:".$sum."<br  />";
Related recommendations:

css, js dice lottery source code

The above is the detailed content of PHP simulation dice implementation code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn