我有两个数组,我想动态构建一系列“if ... then ... else”条件,与第一个数组中的项目数一样多。两个数组总是具有相同数量的项目。
我尝试的关键是我有数十万行将从if then else
检查,所以我希望它在找到结果时中断。
我怎样才能更好地构建它?
$checker = 0; $counter = 0;
while ($checker < 3) {
if ($usersResult[pages] <= $the_score[$counter]) {
echo 'found <br>';
$checker = 5;
}
$counter++;
}
第一个数组
$unique_percentiles[]
array(6) {
[0]=>
int(5)
[1]=>
int(65)
[2]=>
int(80)
[3]=>
int(85)
[4]=>
int(90)
[5]=>
int(95)
}
和第二个数组
$the_score[]
array(6) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "3"
[3]=>
string(1) "4"
[4]=>
string(1) "5"
[5]=>
string(1) "8"
}
答案 0 :(得分:0)
利用foreach迭代
// i consider two arrays $the_score and $unique_percentiles
foreach($the_score as $key=>$val)
{
// you can make condition in two arrays like,
// $val hold the value of first array - $the_score
// and corresponding element of second array is accessible by $unique_percentiles[$key]
if(your_contidion)
{
break;
}
}