2017-01-02 12 views
-1

私は最初の配列の項目の数だけ動的に一連の "if ... then ... else"条件を構築したいところから2つの配列を持っています。どちらの配列も常に同じ量の項目を持ちます。配列アイテムを使って "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" 
} 
+1

のように反復するのforeachを使用してください、あなたは条件何ができるかを説明してください可能性2つの配列を使用して、つまり、tw o配列 –

+0

私はあなたを理解していません、配列内の項目を検索していますか? – funsholaniyi

+0

'$ unique_percentiles'はどこに入りますか?私はあなたの最初のスニペットでそれを表示されません。そして、どうやって、あなたの配列を使いたいのですか? (注意: '$ camelCase'と' $ snake_case'を混ぜてはいけません。一つを選んで一貫して使用してください)。 – Chris

答えて

0

// 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; 
    } 
} 
関連する問題