Custom range, custom operator, custom operation count _ PHP Tutorial

Source: Internet
Author: User
Custom range, custom operator, and number of custom operations .? Php *** question engine: ** @ authorTourmaline * @ copyright (c) 2013, UnaryInc. * classQuestionEngine {*** scope of question * @ varstring $ scope * public $ scopearray (1,
 OptTimes + 1; $ index ++) {$ elements [] = $ this-> randomValue () ;}$ operatorType = strlen ($ this-> operators ); // There are several operators to choose from. // The Assembly formula $ question = ''; for ($ index = 0; $ index <count ($ elements); $ index ++) {$ question. = ''. $ elements [$ index]. ''; // put a number in. if ($ index <count ($ elements)-1) // if it is not the last number, add an operator $ question. = substr ($ this-> operators, mt_rand (0, $ operatorType-1), 1);} eval ('$ Ansible = '. $ question. ';'); if ($ Ansible <0) {// when the result is negative, $ elements = array (); goto start; // requires PHP5.3 support} echo "$ question = ". $ Ansible;}/*** generates a random value in a range ** @ return int */protected function randomValue () {return mt_rand ($ this-> scope [0], $ this-> scope [1]) ;}}

Test

 Generate ();?> Result: 26 + 85 = 111

Http://www.bkjia.com/PHPjc/440112.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/440112.htmlTechArticle? Php/*** question engine: ** @ author Tourmaline * @ copyright (c) 2013, Unary Inc. */class QuestionEngine {/*** scope of question * @ var string $ scope */public $ scope = array (1 ,...

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.