如何使用数组项构造"if then else"?



我有 2 个数组,我想从那里动态构造一系列"如果...然后。。。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"
}

利用 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;
   }
}

最新更新