自定义范围,自定义运算符,自定义运算次数。太牛逼了 randomvalue(); } $operatortype = strlen($this->operators); //有几个运算符供选择 //开始组装算式 $question = ''; for ($index = 0; $index $question.=' ' . $elements[$index] . ' '; //放一个数字进来 if ($index $question.=substr($this->operators, mt_rand(0, $operatortype - 1), 1); } eval('$anwser = ' . $question . ';'); if ($anwser $elements = array(); goto start; //需php5.3的支持 } echo $question= . $anwser; } /** * 产生一个范围内的随机值 * * @return int */ protected function randomvalue() { return mt_rand($this->scope[0], $this->scope[1]); }}
复制代码
generate();?>结果:26 + 85 = 111
复制代码