This article describes the PHP implementation of the web version of the Scissors stone cloth game. Share to everyone for your reference, specific as follows:
<?php * * Created on 2016-11-25 */if (Isset ($_post[' Sub ')) {$what = $_post[' What '];
The array to be entered $my _array = Array ("Scissors", "stone", "cloth");
The winning rule $guize = Array ("Scissors", "cloth"), Array ("cloth", "stone"), Array ("Stone", "Scissors"));
Take the random value in the array $rand _keys = Array_rand ($my _array);
$computer = $my _array[$rand _keys]; echo "your". $what. " VS ". $computer."
<br/> ";
$input = Array ($computer, $what); The input what and the computer randomly generated values are constructed into an array and then judged if (!) is not in the winning rule.
In_array ($what, $my _array)) {echo "Please input scissors, stone, cloth";
Header ("location:index.php");
} if ($computer = = $what) {echo "Oh, deuce";
}elseif (In_array ($input, $guize)) {echo "Computer wins";
}else {echo "you win ~"; }}?> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
The Operation effect chart is as follows:
More about PHP Interested readers can view the site topics: "PHP Data structure and algorithm tutorial", "PHP Array" Operation Techniques Encyclopedia, "PHP string (String) Usage summary", "PHP Programming Algorithm Summary", "PHP Mathematical Calculation Skills Summary", "PHP Ranking algorithm summary", "PHP common traversal algorithm and skills summary", "PHP Regular Expression Usage summary", "PHP operation and operator usage Summary" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.