您好我有以下代码:
function GetID($d1, $d2, $d3, $d4) {
if ($d1 == '3') {
if ($d2 == '3') {
if ($d3 == 1) {
$randval = mt_rand(1,100);
if ($randval >= 1 && $randval <= 33) $weathern = 1;
if ($randval >= 34 && $randval <= 66) $weathern = 3;
if ($randval >= 67 && $randval >= 100) $weathern = 2;
}
elseif ($d3 == 2) {
$randval = mt_rand(1,100);
if ($randval >= 1 && $randval <= 45) $weathern = 1;
if ($randval >= 46 && $randval <= 70) $weathern = 2;
if ($randval >= 71 && $randval <= 100) $weathern = 3;
}
elseif ($d3 == 3) {
$randval = mt_rand(1,100);
if ($randval >= 1 && $randval <= 10) $weathern = 1;
if ($randval >= 11 && $randval <= 35) $weathern = 2;
if ($randval >= 36 && $randval <= 55) $weathern = 3;
if ($randval >= 56 && $randval <= 85) $weathern = 5;
if ($randval >= 86 && $randval <= 100) $weathern = 6;
}
elseif ($d3 == 5) {
$randval = mt_rand(1,100);
if ($randval >= 1 && $randval <= 30) $weathern = 3;
if ($randval >= 31 && $randval <= 45) $weathern = 4;
if ($randval >= 46 && $randval <= 75) $weathern = 6;
if ($randval >= 76 && $randval <= 100) $weathern = 7;
}
elseif ($d3 == 6) {
$randval = mt_rand(1,100);
if ($randval >= 1 && $randval <= 30) $weathern = 5;
if ($randval >= 31 && $randval <= 60) $weathern = 7;
if ($randval >= 61 && $randval <= 75) $weathern = 2;
if ($randval >= 76 && $randval <= 100) $weathern = 3;
}
elseif ($d3 == 7) {
$randval = mt_rand(1,100);
if ($randval >= 1 && $randval <= 35) $weathern = 8;
if ($randval >= 36 && $randval <= 60) $weathern = 5;
if ($randval >= 61 && $randval <= 85) $weathern = 2;
if ($randval >= 86 && $randval <= 100) $weathern = 3;
}
elseif ($d3 == 8) {
$randval = mt_rand(1,100);
if ($randval >= 1 && $randval <= 35) $weathern = 3;
if ($randval >= 36 && $randval <= 60) $weathern = 2;
if ($randval >= 61 && $randval <= 85) $weathern = 1;
if ($randval >= 86 && $randval <= 100) $weathern = 5;
}
}
}
return $weathern;
}
当我调用此函数时:
echo GetID(3, 3, 1, 1);
它按预期工作(我得到数字),但有时它会返回Nothing。
为什么会发生这种情况?
我是PHP的新手,但我没有看到任何问题
答案 0 :(得分:2)
$randval >= 67 && $randval >= 100
错误,请使用
$randval >= 67 && $randval <= 100
代替。