特定の条件で辞書から単語を削除したい。 次回の反復で、辞書は新しいアイテムを計算します。最後のアイテムは削除されているため、再度計算されません。オンザフライでアイテムをダブルループで削除
// sample data
$dict = ['aaa', 'aaan','aba', 'abat', 'ime', 'iso', 'nime', 'tiso',];
$unique = ['abatiso', 'aaanime'];
// could use while to further optimize unset (and remove on the fly) http://php.net/manual/en/control-structures.foreach.php#88578
while (list($key_word, $word) = each($unique)) { // $key is unused, just for the optimization that the whille provides
foreach ($dict as $key_other => $other) {
// ... conditions calculations
unset($unique[$key_word]);
}
}
echo "n compounds: " . count($compounds) . NL;
は、私はしばらくの間、外のように代わりのforeachと内側のループを設定した場合、私は0結果を得る、それがinmediatelyを終了します。今の
、私は次のように重複した結果を取得しています:
// Removed: abatiso => wc: aba + tiso = abatiso // Removed: abatiso => wc: abat + iso = abatiso // Removed: abatiso => wc: abati + so = abatiso // Removed: abatiso => wc: abatis + o = abatiso
どのように私はそれはそれは、単語を削除し、次の反復で再びそれをproccessないだろうことができますか?
いくつかのテストデータ:私も計算をしなければならないので、私は内側のループ内のブレークを使用していない
Removed: aaaaaah => wc: aaaa + aah = aaaaaah
Removed: aaaaaah => wc: aaaaaa + h = aaaaaah
Removed: aaaaargh => wc: aaa + aargh = aaaaargh
Removed: aaaalead => wc: aaaa + lead = aaaalead
Removed: aaabbbccc => wc: aaab + bbccc = aaabbbccc
Removed: aaacomix => wc: aaa + comix = aaacomix
Removed: aaagak => wc: aaa + gak = aaagak
Removed: aaahh => wc: aaa + hh = aaahh
Removed: aaainc => wc: aaa + inc = aaainc
Removed: aaainc => wc: aaai + nc = aaainc
Removed: aaanet => wc: aaa + net = aaanet
Removed: aaanet => wc: aaan + et = aaanet
Removed: aaanime => wc: aaa + nime = aaanime
Removed: aaanime => wc: aaan + ime = aaanime
Removed: aaaron => wc: aaa + ron = aaaron
Removed: aabbcc => wc: aab + bcc = aabbcc
Removed: aabmup => wc: aab + mup = aabmup
Removed: aabre => wc: aab + re = aabre
Removed: aabybro => wc: aaby + bro = aabybro
Removed: aacap => wc: aac + ap = aacap
Removed: aacap => wc: aaca + p = aacap
Removed: aaccording => wc: aac + cording = aaccording
Removed: aacd => wc: aac + d = aacd
Removed: aachener => wc: aach + ener = aachener
Removed: aachener => wc: aachen + er = aachener
Removed: aacisuan => wc: aaci + suan = aacisuan
Removed: aacisuan => wc: aacis + uan = aacisuan
Removed: aacult => wc: aac + ult = aacult
。
あなたの質問や、コードの具体的下さい。 – Eiko
@エイコあなたが理解していないものは? – Cristo
私は現在、「for($ i = 0; $ i
Cristo