21,886
社区成员
发帖
与我相关
我的任务
分享
$strSigns = '+-*/';
$intRandMax = strlen($strSigns) - 1;
$strSign = $strSigns{mt_rand(0, $intRandMax)};
$intResult = 0;
switch($strSign)
{
case '+':
$intResult = $intRand1 + $intRand12;
break;
case '-':
$intResult = $intRand1 - $intRand12;
break;
case '*':
$intResult = $intRand1 * $intRand12;
break;
case '/':
$intResult = $intRand1 / $intRand12;
//这里的除法晕眩会有小数点,你可以用ceil,floor等函数取整,然后告诉浏览者要怎么做除法运算。
break;
}