我不知道如何处理概率抽签
I don't know what to do with the probability draw
我目前是给一个或多个人打分,根据分数选择画一个以上的人。但是,仍然存在运行时错误,并且没有得到解决。请让我知道如何解决这个问题。
这是我的代码:
$selectChildrens = array();
for($i=0;$i<$recuTotal;$i++){
$random = rand(0,sizeof($childSelectArray)-1);
$selectChild = $childSelectArray[$random];
$sameCheck = 0;
if(sizeof($selectChildrens) == 0){
array_push($selectChildrens,$selectChild);
while(($key = array_search($selectChild,$childSelectArray)) != NULL){
unset($childSelectArray[$key]);
}
$recuTotal—;
$i=0;
}else{
array_push($selectChildrens,$selectChild);
while(($key2 = array_search($selectChild,$childSelectArray)) != NULL){
unset($childSelectArray[$key2]);
}
$recuTotal—;
$i=0;
}
}
我看到您尝试递减 $recuTotal
的语法不正确。
改用这一行:$recuTotal--
您使用的是长破折号,但需要两个连字符。
至于你的 array_search()
行,我总是使用:!==false
虽然我不确定它是否重要。
最后,您可以使用 !sizeof($selectChildrens)
作为更短的 if 语句。
尽管我承认我没有完全梳理您的代码以了解它在做什么,但这是一个 DRYer 代码块,其执行方式相同:
$selectChildrens = array();
for($i=0;$i<$recuTotal;$i++){
$random = rand(0,sizeof($childSelectArray)-1);
$selectChild = $childSelectArray[$random];
$sameCheck = 0;
array_push($selectChildrens,$selectChild);
while(($key=array_search($selectChild,$childSelectArray))!==false){
unset($childSelectArray[$key]);
}
$recuTotal--;
$i=0;
}
我目前是给一个或多个人打分,根据分数选择画一个以上的人。但是,仍然存在运行时错误,并且没有得到解决。请让我知道如何解决这个问题。
这是我的代码:
$selectChildrens = array();
for($i=0;$i<$recuTotal;$i++){
$random = rand(0,sizeof($childSelectArray)-1);
$selectChild = $childSelectArray[$random];
$sameCheck = 0;
if(sizeof($selectChildrens) == 0){
array_push($selectChildrens,$selectChild);
while(($key = array_search($selectChild,$childSelectArray)) != NULL){
unset($childSelectArray[$key]);
}
$recuTotal—;
$i=0;
}else{
array_push($selectChildrens,$selectChild);
while(($key2 = array_search($selectChild,$childSelectArray)) != NULL){
unset($childSelectArray[$key2]);
}
$recuTotal—;
$i=0;
}
}
我看到您尝试递减 $recuTotal
的语法不正确。
改用这一行:$recuTotal--
您使用的是长破折号,但需要两个连字符。
至于你的 array_search()
行,我总是使用:!==false
虽然我不确定它是否重要。
最后,您可以使用 !sizeof($selectChildrens)
作为更短的 if 语句。
尽管我承认我没有完全梳理您的代码以了解它在做什么,但这是一个 DRYer 代码块,其执行方式相同:
$selectChildrens = array();
for($i=0;$i<$recuTotal;$i++){
$random = rand(0,sizeof($childSelectArray)-1);
$selectChild = $childSelectArray[$random];
$sameCheck = 0;
array_push($selectChildrens,$selectChild);
while(($key=array_search($selectChild,$childSelectArray))!==false){
unset($childSelectArray[$key]);
}
$recuTotal--;
$i=0;
}