PHP implementation of the web version of the Scissors Stone cloth game sample _php Tips

Source: Internet
Author: User
Tags php programming php regular expression rand

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.